| | |
| | | package com.igo.user.ui.trip |
| | | |
| | | import android.Manifest |
| | | import android.annotation.SuppressLint |
| | | import android.app.Activity |
| | | import android.content.Intent |
| | | import android.content.pm.PackageManager |
| | | import android.graphics.Bitmap |
| | | import android.graphics.Color |
| | | import android.os.Bundle |
| | | import android.os.Handler |
| | | import android.os.Message |
| | |
| | | import android.widget.ImageView |
| | | import android.widget.TextView |
| | | import androidx.appcompat.widget.AppCompatTextView |
| | | import androidx.core.content.ContextCompat |
| | | import androidx.core.app.ActivityCompat |
| | | import androidx.core.os.bundleOf |
| | | import androidx.core.view.isVisible |
| | | import androidx.lifecycle.Lifecycle |
| | | import androidx.lifecycle.lifecycleScope |
| | | import androidx.lifecycle.repeatOnLifecycle |
| | | import androidx.recyclerview.widget.LinearLayoutManager |
| | | import androidx.recyclerview.widget.RecyclerView |
| | | import cn.sinata.rxnetty.LogHelper |
| | | import cn.sinata.rxnetty.LogHelper.logRecord |
| | | import cn.sinata.rxnetty.NettyClient |
| | | import cn.sinata.xldutils.activity.BaseActivity |
| | | import cn.sinata.xldutils.callPhone |
| | | import cn.sinata.xldutils.gone |
| | | import cn.sinata.xldutils.utils.SPUtils |
| | | import cn.sinata.xldutils.utils.LanguageUtil |
| | | import cn.sinata.xldutils.utils.SpanBuilder |
| | | import cn.sinata.xldutils.utils.myToast |
| | | import cn.sinata.xldutils.utils.parserTime |
| | |
| | | import com.google.android.gms.maps.model.Marker |
| | | import com.google.android.gms.maps.model.MarkerOptions |
| | | import com.google.android.gms.maps.model.Polyline |
| | | import com.google.android.gms.maps.model.PolylineOptions |
| | | import com.google.android.libraries.mapsplatform.transportation.consumer.ConsumerApi |
| | | import com.google.android.libraries.mapsplatform.transportation.consumer.managers.TripModelCallback |
| | | import com.google.android.libraries.mapsplatform.transportation.consumer.managers.TripModelManager |
| | | import com.google.android.libraries.mapsplatform.transportation.consumer.model.MarkerType |
| | | import com.google.android.libraries.mapsplatform.transportation.consumer.model.TripInfo |
| | | import com.google.android.libraries.mapsplatform.transportation.consumer.model.TripInfo.TripStatus |
| | |
| | | import com.google.gson.Gson |
| | | import com.google.gson.reflect.TypeToken |
| | | import com.igo.user.IGoApplication |
| | | import com.igo.user.IGoApplication.Companion.address |
| | | import com.igo.user.IGoApplication.Companion.phone |
| | | import com.igo.user.R |
| | | import com.igo.user.dialog.ShareDialog |
| | | import com.igo.user.dialog.TipDialog |
| | | import com.igo.user.interfaces.OrderStateChangeListener |
| | | import com.igo.user.network.Apis |
| | | import com.igo.user.network.HttpManager |
| | | import com.igo.user.network.entity.Order |
| | | import com.igo.user.network.entity.Point |
| | | import com.igo.user.network.entity.RouteBean |
| | | import com.igo.user.network.entity.TrippingInfo |
| | | import com.igo.user.network.request |
| | | import com.igo.user.ui.mine.TripOrderFragment |
| | | import com.igo.user.ui.trip.adapter.ProgressAdapter |
| | | import com.igo.user.utils.Const |
| | | import com.igo.user.utils.Const.OrderType.TYPE_SPECIAL |
| | | import com.igo.user.utils.IGoShareUtils |
| | | import com.igo.user.utils.google.AMapKit |
| | | import com.igo.user.utils.google.JsonAuthTokenFactory |
| | | import com.share.utils.ShareUtils |
| | | import com.tbruyelle.rxpermissions2.RxPermissions |
| | | import com.umeng.socialize.UMShareListener |
| | | import com.umeng.socialize.bean.SHARE_MEDIA |
| | | import com.umeng.socialize.media.UMImage |
| | | import io.reactivex.subscribers.DisposableSubscriber |
| | | import kotlinx.coroutines.Dispatchers |
| | | import kotlinx.coroutines.launch |
| | | import org.jetbrains.anko.dip |
| | | import org.jetbrains.anko.find |
| | | import org.jetbrains.anko.imageResource |
| | |
| | | import org.jetbrains.anko.startActivity |
| | | import org.jetbrains.anko.startActivityForResult |
| | | |
| | | class TripActivity : BaseActivity(), Handler.Callback, OrderStateChangeListener, UMShareListener { |
| | | lateinit var aMap: ConsumerGoogleMap |
| | | class TripActivity : BaseActivity(), Handler.Callback, |
| | | OrderStateChangeListener { |
| | | var aMap: ConsumerGoogleMap? = null |
| | | |
| | | override fun onCreate(savedInstanceState: Bundle?) { |
| | | super.onCreate(savedInstanceState) |
| | |
| | | ) |
| | | tipDialog.setCallback(object : TipDialog.OnClickCallback { |
| | | override fun onOk() { |
| | | LogHelper.logRecord("继续等待订单接单orderId:${id} orderType:${type}") |
| | | HttpManager.pushOrderTaxi(id, type).request(this@TripActivity, success = { _, _ -> |
| | | LogHelper.logRecord("继续等待订单被接单成功orderId:${id} orderType:${type}") |
| | | }) { code, msg -> |
| | | LogHelper.logRecord("继续等待订单被接单失败orderId:${id} orderType:${type} code:${code} msg:${msg}") |
| | | } |
| | | } |
| | | |
| | | override fun onCancel() { |
| | | cancelOrder() |
| | | } |
| | | }) |
| | | tipDialog.setDismissCallback(object : TipDialog.OnDismiss { |
| | | override fun onDismiss() { |
| | | HttpManager.pushOrderTaxi(id, type).request(this@TripActivity) { _, _ -> |
| | | } |
| | | } |
| | | }) |
| | | tipDialog |
| | |
| | | private val tv_time by lazy { find<TextView>(R.id.tv_time) } |
| | | private val tv_passenger_num by lazy { find<TextView>(R.id.tv_passenger_num) } |
| | | private val tv_remark by lazy { find<TextView>(R.id.tv_remark) } |
| | | private val ll_receiver_goods_code by lazy { find<View>(R.id.ll_receiver_goods_code) } |
| | | private val tv_receiver_goods_code by lazy { find<TextView>(R.id.tv_receiver_goods_code) } |
| | | private val tv_state by lazy { find<TextView>(R.id.tv_state) } |
| | | private val cl_driver by lazy { find<View>(R.id.cl_driver) } |
| | | private val tv_name by lazy { find<TextView>(R.id.tv_name) } |
| | |
| | | |
| | | |
| | | private var consumerApi: ConsumerApi? = null //谷歌消费者sdk |
| | | private var tripModelManager: TripModelManager? = null |
| | | private var session: JourneySharingSession? = null |
| | | |
| | | private val progressList = arrayListOf<String>() |
| | |
| | | |
| | | fun initClick() { |
| | | iv_shuaxing.onClick { |
| | | Log.e("订单信息: ", id.toString()) |
| | | Log.e("订单信息: ", type.toString()) |
| | | LogHelper.logRecord("刷新行驶数据orderId:${id} orderType:${type}") |
| | | HttpManager.getOrderDrivingData(id, type) |
| | | .request(this@TripActivity, false, { _, _ -> |
| | | }) { _, msg -> |
| | | |
| | | var data = gson.fromJson(msg, TrippingInfo::class.java) |
| | | Log.e("订单信息: ", data.toString()) |
| | | setTrippingUI(data) |
| | | .request(this@TripActivity, false, { _, data -> |
| | | LogHelper.logRecord("获取行驶数据成功orderId:${id} orderType:${type} data:${data}") |
| | | data?.also { |
| | | setTrippingUI(it) |
| | | } |
| | | }) { code, msg -> |
| | | LogHelper.logRecord("获取行驶数据失败orderId:${id} orderType:${type} code:${code} msg:${msg}") |
| | | } |
| | | |
| | | } |
| | | tv_complain.onClick { |
| | | startActivity<ComplainActivity>("id" to order!!.driverId) |
| | | order?.also { |
| | | startActivity<ComplainActivity>("id" to it.driverId) |
| | | } |
| | | } |
| | | |
| | | tv_action.setOnClickListener { |
| | |
| | | } |
| | | |
| | | iv_call.setOnClickListener { |
| | | callPhone(order?.driverPhone) |
| | | order?.driverPhone?.takeIf { it.isNotEmpty() }?.also { callPhone(it) } |
| | | } |
| | | |
| | | tv_110.setOnClickListener { |
| | | callPhone(phoneEmergency) |
| | | phoneEmergency.takeIf { it.isNotEmpty() }?.also { callPhone(it) } |
| | | } |
| | | tv_service.setOnClickListener { |
| | | callPhone(phoneService) |
| | | phoneService.takeIf { it.isNotEmpty() }?.also { callPhone(it) } |
| | | } |
| | | |
| | | /*tv_share.onClick { |
| | | val shareDialog = ShareDialog() |
| | | shareDialog.arguments = bundleOf("isTrip" to true) |
| | | shareDialog.setCallback(object :ShareDialog.Callback{ |
| | | override fun onOk(way: Int) { |
| | | val language = SPUtils.instance().getString("language") |
| | | val languageP = if (language == "ch") 1 else if(language == "fr") 3 else 2 |
| | | val url = String.format(Apis.TRIP_URL,languageP,id.toString(),type,languageP) |
| | | if (way == 3) |
| | | IGoShareUtils.shareWA(this@TripActivity,getString(R.string.行程分享内容,SPUtils.instance().getString(Const.User.PHONE)),url) |
| | | else |
| | | if (way == 4) |
| | | IGoShareUtils.shareFB(this@TripActivity,url,getString(R.string.行程分享内容,SPUtils.instance().getString(Const.User.PHONE)),null) |
| | | else if (way == 5) |
| | | IGoShareUtils.shareTweet(this@TripActivity,getString(R.string.行程分享内容,SPUtils.instance().getString(Const.User.PHONE)),url) |
| | | else if (way == 1) |
| | | ShareUtils.share(this@TripActivity,SHARE_MEDIA.WEIXIN_CIRCLE, getString(R.string.行程分享内容,SPUtils.instance().getString(Const.User.PHONE)), |
| | | getString(R.string.行程分享内容,SPUtils.instance().getString(Const.User.PHONE)),url, UMImage(this@TripActivity,R.mipmap.ic_share_trip),this@TripActivity,IGoApplication.emergency) |
| | | else |
| | | ShareUtils.share(this@TripActivity,if (way == 0) SHARE_MEDIA.WEIXIN else if (way == 1) SHARE_MEDIA.WEIXIN_CIRCLE else |
| | | SHARE_MEDIA.MORE, getString(R.string.行程分享内容,SPUtils.instance().getString(Const.User.PHONE)), |
| | | Const.Share.TITLE,url, UMImage(this@TripActivity,R.mipmap.ic_share_trip),this@TripActivity,IGoApplication.emergency) |
| | | shareDialog.dismiss() |
| | | } |
| | | }) |
| | | shareDialog.show(supportFragmentManager,"share") |
| | | }*/ |
| | | |
| | | iv_header_home.setOnClickListener { |
| | | startActivity<DriverDetailActivity>("id" to order!!.driverId) |
| | | order?.also { |
| | | startActivity<DriverDetailActivity>("id" to it.driverId) |
| | | } |
| | | } |
| | | |
| | | iv_location.setOnClickListener { |
| | | if (order?.state == 5 && vehicleLocation != null) { |
| | | aMap.animateCamera( |
| | | aMap?.animateCamera( |
| | | CameraUpdateFactory.newLatLngZoom( |
| | | LatLng( |
| | | vehicleLocation!!.latLng.latitude, |
| | |
| | | ) |
| | | ) |
| | | } else |
| | | aMap.animateCamera( |
| | | CameraUpdateFactory.newLatLngZoom( |
| | | LatLng( |
| | | IGoApplication.lat, |
| | | IGoApplication.lon |
| | | ), 18f |
| | | ) |
| | | aMap?.animateCamera( |
| | | CameraUpdateFactory.newLatLngZoom(IGoApplication.getCurrentLocation(), 18f) |
| | | ) |
| | | handler.removeMessages(4) |
| | | consumerController?.isAutoCameraEnabled = false |
| | |
| | | } |
| | | |
| | | tv_cancel.setOnClickListener { |
| | | val tipDialog = TipDialog() |
| | | tipDialog.arguments = bundleOf( |
| | | "msg" to getString(R.string.未达取消), |
| | | "ok" to getString(R.string.确认), "cancel" to getString(R.string.拒绝) |
| | | ) |
| | | tipDialog.setCallback(object : TipDialog.OnClickCallback { |
| | | override fun onOk() { |
| | | startActivityForResult<CancelOrderActivity>( |
| | | 1, "id" to id, "type" to type, "timeOut" to order?.timeOutCancel, |
| | | "driverTimeOut" to order?.driverTimeOut, "state" to order?.state |
| | | ) |
| | | } |
| | | order?.also { |
| | | val tipDialog = TipDialog() |
| | | tipDialog.arguments = bundleOf( |
| | | "msg" to getString(R.string.未达取消), |
| | | "ok" to getString(R.string.确认), "cancel" to getString(R.string.拒绝) |
| | | ) |
| | | tipDialog.setCallback(object : TipDialog.OnClickCallback { |
| | | override fun onOk() { |
| | | startActivityForResult<CancelOrderActivity>( |
| | | 1, "id" to id, "type" to type, "timeOut" to it.timeOutCancel, |
| | | "driverTimeOut" to it.driverTimeOut, "state" to it.state |
| | | ) |
| | | } |
| | | |
| | | override fun onCancel() { |
| | | } |
| | | }) |
| | | tipDialog.show(supportFragmentManager, "cancel") |
| | | override fun onCancel() { |
| | | } |
| | | }) |
| | | tipDialog.show(supportFragmentManager, "cancel") |
| | | } |
| | | } |
| | | |
| | | tv_progress.setOnClickListener { |
| | |
| | | } |
| | | |
| | | private fun cancelOrder() { |
| | | var lat = 0.0 |
| | | var lon = 0.0 |
| | | var lat: Double |
| | | var lon: Double |
| | | if (vehicleLocation == null) { |
| | | lat = IGoApplication.lat |
| | | lon = IGoApplication.lon |
| | | val currentLocation = IGoApplication.getCurrentLocation() |
| | | lat = currentLocation.latitude |
| | | lon = currentLocation.longitude |
| | | } else { |
| | | lat = vehicleLocation!!.latLng.latitude |
| | | lon = vehicleLocation!!.latLng.longitude |
| | | } |
| | | HttpManager.cancelOrder(lat, lon, id, type).request(this) { _, _ -> |
| | | LogHelper.logRecord("取消订单,不在继续等待订单被接单orderId:${id} orderType:${type}") |
| | | HttpManager.cancelOrder(lat, lon, id, type).request(this, success = { _, _ -> |
| | | myToast(getString(R.string.取消成功)) |
| | | setResult(Activity.RESULT_OK) |
| | | logRecord("取消订单成功orderId:${id} type:${type}") |
| | | setResult(RESULT_OK) |
| | | finish() |
| | | }) { code, msg -> |
| | | logRecord("取消订单失败orderId:${id} type:${type} code:${code} msg:${msg}") |
| | | } |
| | | } |
| | | |
| | |
| | | .create().immersionBar() //沉浸状态栏 |
| | | id = intent.getIntExtra("id", 0) |
| | | type = intent.getIntExtra("type", Const.OrderType.TYPE_TAXI) |
| | | logRecord("订单进行中orderId:${id} type:${type}") |
| | | titleBar.addRightButton( |
| | | getString(R.string.取消订单), |
| | | onClickListener = View.OnClickListener { |
| | | if (titleBar.getRightButton(0)?.text == getString(R.string.取消订单)) |
| | | startActivityForResult<CancelOrderActivity>( |
| | | 1, "id" to id, "type" to type, "timeOut" to order?.timeOutCancel, |
| | | "driverTimeOut" to order?.driverTimeOut, "state" to order?.state |
| | | ) |
| | | else if (titleBar.getRightButton(0)?.text == getString(R.string.投诉司机)) |
| | | tv_complain.callOnClick() |
| | | else |
| | | startActivityForResult<ChoosePositionActivity>(2, "isModify" to true) |
| | | when (titleBar.getRightButton(0)?.text) { |
| | | getString(R.string.取消订单) -> { |
| | | order?.also { |
| | | startActivityForResult<CancelOrderActivity>( |
| | | 1, "id" to id, "type" to type, "timeOut" to it.timeOutCancel, |
| | | "driverTimeOut" to it.driverTimeOut, "state" to it.state |
| | | ) |
| | | } |
| | | } |
| | | |
| | | getString(R.string.投诉司机) -> { |
| | | tv_complain.callOnClick() |
| | | } |
| | | |
| | | else |
| | | -> startActivityForResult<ChoosePositionActivity>(2, "isModify" to true) |
| | | } |
| | | }) |
| | | titleBar.getRightButton(0)?.gone() |
| | | initConsumerSdk() |
| | | initMap() |
| | | enableMyLocation() |
| | | app.addTripStateListener(this) |
| | | getPhone() |
| | | rv_progress.layoutManager = LinearLayoutManager(this) |
| | |
| | | |
| | | private fun initConsumerSdk() { |
| | | //谷歌乘客端api初始化 |
| | | val consumerApiTask = ConsumerApi.initialize( |
| | | this, Const.google_provider_id, |
| | | JsonAuthTokenFactory() |
| | | ) |
| | | val consumerApiTask = |
| | | ConsumerApi.initialize(this, Const.google_provider_id, JsonAuthTokenFactory()) |
| | | consumerApiTask?.addOnSuccessListener { consumerApi: ConsumerApi -> |
| | | Log.e(Const.GoogleTag, "ConsumerApi初始化成功") |
| | | this.consumerApi = consumerApi |
| | | tripModelManager = consumerApi.tripModelManager |
| | | } |
| | | } |
| | | |
| | |
| | | val fragment = supportFragmentManager.findFragmentById(R.id.mMapView) as ConsumerMapFragment |
| | | fragment.getConsumerGoogleMapAsync(object : ConsumerGoogleMap.ConsumerMapReadyCallback() { |
| | | override fun onConsumerMapReady(consumerGoogleMap: ConsumerGoogleMap) { |
| | | if (ActivityCompat.checkSelfPermission( |
| | | this@TripActivity, |
| | | Manifest.permission.ACCESS_FINE_LOCATION |
| | | ) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission( |
| | | this@TripActivity, |
| | | Manifest.permission.ACCESS_COARSE_LOCATION |
| | | ) != PackageManager.PERMISSION_GRANTED |
| | | ) { |
| | | logRecord("没有定位权限orderId:${id} type:${type}") |
| | | return |
| | | } |
| | | consumerController = consumerGoogleMap.consumerController!! |
| | | val markerOptions = MarkerOptions() |
| | | markerOptions.icon(BitmapDescriptorFactory.fromResource(R.mipmap.location_car)) |
| | |
| | | markerOptions |
| | | ) |
| | | // consumerController?.isAutoCameraEnabled = false |
| | | aMap = consumerGoogleMap |
| | | aMap.setPadding(0, dip(120), 0, dip(70)) |
| | | enableMyLocation() |
| | | aMap.uiSettings.isMyLocationButtonEnabled = false |
| | | aMap.moveCamera( |
| | | CameraUpdateFactory.newLatLng( |
| | | LatLng( |
| | | IGoApplication.lat, |
| | | IGoApplication.lon |
| | | ) |
| | | ) |
| | | ) |
| | | aMap.setOnCameraMoveStartedListener { |
| | | if (it == GoogleMap.OnCameraMoveStartedListener.REASON_GESTURE) { |
| | | handler.removeMessages(4) |
| | | consumerController?.isAutoCameraEnabled = false |
| | | aMap = consumerGoogleMap.apply { |
| | | isMyLocationEnabled = true |
| | | setPadding(0, dip(120), 0, dip(70)) |
| | | uiSettings.isMyLocationButtonEnabled = false |
| | | moveCamera(CameraUpdateFactory.newLatLng(IGoApplication.getCurrentLocation())) |
| | | setOnCameraMoveStartedListener { |
| | | if (it == GoogleMap.OnCameraMoveStartedListener.REASON_GESTURE) { |
| | | handler.removeMessages(4) |
| | | consumerController?.isAutoCameraEnabled = false |
| | | } |
| | | } |
| | | //地图相机(视角)停止移动并变为空闲状态时触发回调 |
| | | setOnCameraIdleListener { |
| | | handler.sendEmptyMessageDelayed(4, 10000) |
| | | } |
| | | } |
| | | //地图相机(视角)停止移动并变为空闲状态时触发回调 |
| | | aMap.setOnCameraIdleListener { |
| | | handler.sendEmptyMessageDelayed(4, 10000) |
| | | } |
| | | getData() |
| | | } |
| | | }) |
| | | } |
| | |
| | | /** |
| | | * Enables the My Location layer if the fine location permission has been granted. |
| | | */ |
| | | @SuppressLint("MissingPermission") |
| | | private fun enableMyLocation() { |
| | | // 1. Check if permissions are granted, if so, enable the my location layer |
| | | if (ContextCompat.checkSelfPermission( |
| | | this, |
| | | Manifest.permission.ACCESS_FINE_LOCATION |
| | | ) == PackageManager.PERMISSION_GRANTED || |
| | | ContextCompat.checkSelfPermission( |
| | | this, |
| | | Manifest.permission.ACCESS_COARSE_LOCATION |
| | | ) == PackageManager.PERMISSION_GRANTED |
| | | ) { |
| | | aMap.isMyLocationEnabled = true |
| | | return |
| | | } |
| | | // 2. If if a permission rationale dialog should be shown //todo 权限说明弹窗 |
| | | // if (ActivityCompat.shouldShowRequestPermissionRationale( |
| | | // this, |
| | | // Manifest.permission.ACCESS_FINE_LOCATION |
| | | // ) || ActivityCompat.shouldShowRequestPermissionRationale( |
| | | // this, |
| | | // Manifest.permission.ACCESS_COARSE_LOCATION |
| | | // ) |
| | | // ) { |
| | | // PermissionUtils.RationaleDialog.newInstance( |
| | | // LOCATION_PERMISSION_REQUEST_CODE, true |
| | | // ).show(supportFragmentManager, "dialog") |
| | | // return |
| | | // } |
| | | val subscribe = RxPermissions(this).request( |
| | | Manifest.permission.ACCESS_FINE_LOCATION, |
| | | Manifest.permission.ACCESS_COARSE_LOCATION |
| | | ).subscribe { |
| | | if (it) |
| | | enableMyLocation() |
| | | initMap() |
| | | else { |
| | | myToast(getString(R.string.没有权限)) |
| | | logRecord("用户没有授予定位权限orderId:${id} type:${type}") |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | private fun getPhone() { |
| | | HttpManager.getPhone(IGoApplication.lat, IGoApplication.lon) |
| | | val currentLocation = IGoApplication.getCurrentLocation() |
| | | HttpManager.getPhone(currentLocation.latitude, currentLocation.longitude) |
| | | .request(this, false) { _, data -> |
| | | data?.let { |
| | | it.forEach { |
| | | if (it.type == 1) |
| | | phoneEmergency = it.phone |
| | | else if (it.type == 2) |
| | | phoneService = it.phone |
| | | } |
| | | data?.forEach { |
| | | if (it.type == 1) |
| | | phoneEmergency = it.phone |
| | | else if (it.type == 2) |
| | | phoneService = it.phone |
| | | } |
| | | } |
| | | } |
| | |
| | | /** |
| | | * 获取订单基础数据:起终点,订单状态等 |
| | | */ |
| | | private var lastMin = 0 //剩余到达分钟 |
| | | private var lastDistance = 0 //剩余距离米 |
| | | private fun getData() { |
| | | HttpManager.queryOrderInfo(id, type).request(this) { _, data -> |
| | | order = data |
| | |
| | | // Add the JourneySharingSession instance on the map for updating the UI. |
| | | consumerController?.showSession(session!!) |
| | | tripModel.registerTripCallback(object : TripModelCallback() { |
| | | // override fun onTripETAToNextWaypointUpdated( |
| | | // tripInfo: TripInfo, |
| | | // timestampMillis: Long?, |
| | | // ) { |
| | | // // ... |
| | | // } |
| | | // |
| | | // override fun onTripActiveRouteRemainingDistanceUpdated( |
| | | // tripInfo: TripInfo, |
| | | // distanceMeters: Int?, |
| | | // ) { |
| | | // // ... |
| | | // } |
| | | |
| | | override fun onTripStatusUpdate(p0: TripInfo, p1: Int) { |
| | | super.onTripStatusUpdate(p0, p1) |
| | | Log.e(Const.GoogleTag, "onTripStatusUpdate:${p1}") |
| | |
| | | |
| | | override fun onTripUpdated(p0: TripInfo) { |
| | | super.onTripUpdated(p0) |
| | | lastMin = (((p0.dropoffTimeMillis |
| | | ?: 0L) - System.currentTimeMillis()) / 1000 / 60).toInt() |
| | | lastDistance = p0.activeRouteRemainingDistanceMeters ?: 0 |
| | | Log.e( |
| | | Const.GoogleTag, |
| | | "onTripUpdated:${lastMin}分钟,;;${p0.activeRouteRemainingDistanceMeters}米" |
| | | "onTripUpdated:${p0.vehicleLocation?.latLng}" |
| | | ) |
| | | vehicleLocation = p0.vehicleLocation |
| | | vehicleLocation?.let { |
| | | IGoApplication.lat = it.latLng.latitude |
| | | IGoApplication.lon = it.latLng.longitude |
| | | } |
| | | } |
| | | |
| | | |
| | | }) |
| | | // Set refresh interval to 2 seconds. |
| | | val tripOptions = |
| | | TripModelOptions.builder().setRefreshIntervalMillis(2000).build() |
| | | tripModel.tripModelOptions = tripOptions |
| | | } catch (e: Exception) { |
| | | e.printStackTrace() |
| | | Log.e(Const.GoogleTag, e.message ?: "用户sdk初始化异常") |
| | | } |
| | | } |
| | |
| | | } |
| | | if (type == Const.OrderType.TYPE_SAME_CITY) { |
| | | tv_passenger_num.visible() |
| | | tv_passenger_num.text = if (it.remark.isNullOrEmpty()) "——" else it.remark |
| | | /* if (it.state in 2..6) { |
| | | |
| | | tv_progress.visible() |
| | | |
| | | line.visible() |
| | | }*/ |
| | | tv_passenger_num.text = it.remark.ifEmpty { "——" } |
| | | } |
| | | if (it.state != 1) { //有司机 |
| | | handler.removeMessages(0) |
| | |
| | | */ |
| | | private fun setStateUI() { |
| | | iv_shuaxing.gone() |
| | | ll_receiver_goods_code.isVisible = false |
| | | order?.let { |
| | | when (it.state) { |
| | | 1 -> { |
| | | logRecord("订单处于等待应答状态:${order}") |
| | | titleBar.getRightButton(0)?.visible() |
| | | titleBar.setTitle(getString(R.string.等待应答)) |
| | | if (!handler.hasMessages(0)) |
| | | handler.sendEmptyMessage(0) |
| | | tv_action.visible() |
| | | aMap.animateCamera( |
| | | aMap?.animateCamera( |
| | | CameraUpdateFactory.newLatLngZoom( |
| | | LatLng( |
| | | it.startLat, |
| | | it.startLon |
| | | ), 18f |
| | | LatLng(it.startLat, it.startLon), 18f |
| | | ) |
| | | ) |
| | | queryEndPush() |
| | | } |
| | | |
| | | 2 -> { |
| | | logRecord( |
| | | "订单处于等待${ |
| | | if (type == TripOrderFragment.TYPE_LOGISTICS) { |
| | | "取件" |
| | | } else { |
| | | "接驾" |
| | | } |
| | | }状态:${order}" |
| | | ) |
| | | if (type == TripOrderFragment.TYPE_LOGISTICS) |
| | | titleBar.getRightButton(0)?.gone() |
| | | titleBar.setTitle( |
| | |
| | | } |
| | | |
| | | 3 -> { |
| | | logRecord( |
| | | "订单处于司机前往${ |
| | | if (type == TripOrderFragment.TYPE_LOGISTICS) { |
| | | "取件点" |
| | | } else { |
| | | "接驾点" |
| | | } |
| | | }状态:${order}" |
| | | ) |
| | | titleBar.getRightButton(0)?.gone() |
| | | titleBar.setTitle( |
| | | getString( |
| | |
| | | } |
| | | |
| | | 4 -> { |
| | | logRecord( |
| | | "订单处于司机已到达${ |
| | | if (type == TripOrderFragment.TYPE_LOGISTICS) { |
| | | "取件点" |
| | | } else { |
| | | "接驾点" |
| | | } |
| | | }状态:${order}" |
| | | ) |
| | | titleBar.getRightButton(0)?.gone() |
| | | println("隐藏取消订单") |
| | | titleBar.setTitle(getString(R.string.司机已到达)) |
| | |
| | | } |
| | | |
| | | 5 -> { |
| | | logRecord( |
| | | "订单处于司机${ |
| | | if (type == TripOrderFragment.TYPE_LOGISTICS) { |
| | | "送货中" |
| | | } else { |
| | | "服务中" |
| | | } |
| | | }状态:${order}" |
| | | ) |
| | | if (type == TYPE_SPECIAL) |
| | | iv_shuaxing.visible() else iv_shuaxing.gone() |
| | | titleBar.setTitle(getString(R.string.serving)) |
| | |
| | | tv_cancel.gone() |
| | | } //客户反馈:快件单一旦司机开始行程后(取到快件送货途中)就不能再取消订单 |
| | | titleBar.getRightButton(0)?.gone() |
| | | aMap.isMyLocationEnabled = false //行程中取消乘客定位 |
| | | aMap?.isMyLocationEnabled = false //行程中取消乘客定位 |
| | | drawLine() |
| | | ll_receiver_goods_code.isVisible = it.orderType == Const.OrderType.TYPE_SAME_CITY |
| | | tv_receiver_goods_code.text = getString(R.string.取件码) + (it.code ?: "") |
| | | } |
| | | |
| | | 10 -> { |
| | | logRecord("订单处于已取消状态:${order}") |
| | | if (it.cancelUserType != 1) { |
| | | startActivity<OrderCancelDetailActivity>("id" to id, "type" to type) |
| | | finish() |
| | |
| | | } |
| | | |
| | | else -> { |
| | | logRecord("订单处于状态state=${it.state}:${order}") |
| | | startActivity<OrderDetailActivity>("id" to id, "type" to type) |
| | | finish() |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | private fun drawLine() { |
| | | if (order?.orderType == 4) return // 快件订单不绘制 |
| | | if (startMarker != null && endMarker != null) { |
| | | LogHelper.logRecord("开始规划路线") |
| | | AMapKit.initRouteLine( |
| | | startMarker!!.position, |
| | | endMarker!!.position, |
| | | object : (MutableList<LatLng>, Float, Long) -> Unit { |
| | | override fun invoke(p1: MutableList<LatLng>, p2: Float, p3: Long) { |
| | | if (isFinishing || isDestroyed) { |
| | | LogHelper.logRecord("订单行程页已经关闭") |
| | | return |
| | | } |
| | | aMap?.also { |
| | | markerLine?.remove() |
| | | LogHelper.logRecord("开始绘制规划路线 ${p1.size}") |
| | | markerLine = AMapKit.drawLine(this@TripActivity, it, p1) |
| | | AMapKit.moveCamera(it, startMarker!!.position, endMarker!!.position) |
| | | } |
| | | } |
| | | }) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取行程中的数据:主要是司机位置,订单状态变化,距离、时间等预算信息 |
| | |
| | | IGoApplication.intervalCount = 0 |
| | | HttpManager.trippingInfo(id, type).request(this) { _, data -> |
| | | data?.let { |
| | | if (it.lat.isNotEmpty()) |
| | | setDriverMarker(LatLng(it.lat.toDouble(), it.lon.toDouble())) |
| | | if (!it.lat.isNullOrEmpty()) |
| | | setDriverMarker(LatLng(it.lat.toDouble(), it.lon?.toDoubleOrNull() ?: 0.0)) |
| | | if (it.state != order?.state) //订单状态发生变化,重新拉取数据 |
| | | getData() |
| | | else { |
| | |
| | | * 超时无应答 |
| | | */ |
| | | fun noResponse(id: Int) { |
| | | if (id == this@TripActivity.id && !noResponseDialog.isAdded) { |
| | | noResponseDialog.show(supportFragmentManager, "noResponse") |
| | | if (isFinishing || isDestroyed) { |
| | | return |
| | | } |
| | | lifecycleScope.launch(Dispatchers.Main) { |
| | | // 等待生命周期至少达到 RESUMED(即 onResume 之后) |
| | | if (id == this@TripActivity.id && !noResponseDialog.isAdded) { |
| | | repeatOnLifecycle(Lifecycle.State.RESUMED) { |
| | | noResponseDialog.show(supportFragmentManager, "noResponse") |
| | | LogHelper.logRecord("显示超时无应答弹窗orderId:${id} orderType:${type}") |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | * 行程中的UI,展示不同状态下的动态数据 |
| | | * */ |
| | | private fun setTrippingUI(it: TrippingInfo) { |
| | | tv_state.isVisible = false |
| | | //订单状态(1=待接单,2=待出发,3=待到达预约地点,4=待乘客上车,5=服务中,6=完成服务, |
| | | // 7=待支付,8=待评价,9=已完成,10=已取消,11=改派中,12=取消待支付)加个15作为改派成功 |
| | | when (order?.state) { |
| | | 2, 3 -> { |
| | | if ((it.reservationMileage.isNullOrEmpty() || it.reservationMileage.toDouble() == 0.0) |
| | | && (it.reservationTime.isNullOrEmpty() || it.reservationTime.toInt() == 0) |
| | | ) { //无数据 |
| | | tv_state.text = getString(R.string.司机接驾途中) |
| | | } else { |
| | | val time = getString(R.string.多少分钟, it.reservationTime) |
| | | val distance = "%.2f".format(it.reservationMileage.toDouble()) |
| | | val s = getString(R.string.接驾中, distance, time) |
| | | tv_state.text = SpanBuilder(s).color( |
| | | this, s.indexOf(distance), s.indexOf(distance) + distance.length, |
| | | R.color.colorPrimary |
| | | ).color( |
| | | this, |
| | | s.indexOf(time), |
| | | s.indexOf(time) + it.reservationTime.length, |
| | | R.color.colorPrimary |
| | | ).build() |
| | | } |
| | | |
| | | if (it.lat.isNotEmpty()) { |
| | | //todo 移动视角吗?不需要,因为查询路径后做了移动 |
| | | // val builder = LatLngBounds.builder() |
| | | // builder.include(LatLng(order!!.startLat,order!!.startLon)).include( |
| | | // LatLng(it.lat.toDouble(),it.lon.toDouble())) |
| | | |
| | | if (order?.state == 2) { |
| | | // aMap.animateCamera(CameraUpdateFactory.newLatLngZoom(LatLng(it.lat.toDouble(),it.lon.toDouble()),25f)) |
| | | if (order?.orderType != 4) { // 非快件订单才显示订单状态 |
| | | tv_state.isVisible = true |
| | | if ((it.reservationMileage.isNullOrEmpty() || it.reservationMileage.toDouble() == 0.0) |
| | | && (it.reservationTime.isNullOrEmpty() || it.reservationTime.toInt() == 0) |
| | | ) { //无数据 |
| | | tv_state.text = getString(R.string.司机接驾途中) |
| | | } else { |
| | | val time = getString(R.string.多少分钟, it.reservationTime) |
| | | val distance = "%.2f".format(it.reservationMileage?.toDoubleOrNull() ?: 0.0) |
| | | val s = getString(R.string.接驾中, distance, time) |
| | | tv_state.text = SpanBuilder(s).color( |
| | | this, s.indexOf(distance), s.indexOf(distance) + distance.length, |
| | | R.color.colorPrimary |
| | | ).color( |
| | | this, |
| | | s.indexOf(time), |
| | | s.indexOf(time) + (it.reservationTime ?: "").length, |
| | | R.color.colorPrimary |
| | | ).build() |
| | | } |
| | | if (order?.state == 3) |
| | | setRoute( |
| | | it.lat.toDouble(), it.lon.toDouble(), |
| | | order!!.startLat, order!!.startLon |
| | | ) |
| | | } |
| | | } |
| | | |
| | | 4 -> { |
| | | // aMap.animateCamera(CameraUpdateFactory.newLatLngZoom(LatLng(it.lat.toDouble(),it.lon.toDouble()), 15f)) |
| | | // oldDrivingRouteOverlay?.remove() |
| | | // newDrivingRouteOverlay?.remove() |
| | | tv_state.isVisible = true |
| | | } |
| | | |
| | | 5, 6 -> { |
| | | // val mile2 = "%.2f".format(it.servedMileage.toDouble()) |
| | | // val timeS = getString(R.string.多少分钟,it.laveTime) |
| | | // val s = getString(R.string.已服务时间,it.servedTime, mile2,it.laveMileage,timeS) |
| | | // tv_state.text = SpanBuilder(s).color(this,s.indexOf(it.servedTime),s.indexOf(it.servedTime)+it.servedTime.length,R.color.colorPrimary) |
| | | // .color(this,s.indexOf(mile2),s.indexOf(mile2)+mile2.length,R.color.colorPrimary) |
| | | // .color(this,s.indexOf(it.laveMileage),s.indexOf(it.laveMileage)+it.laveMileage.length,R.color.colorPrimary) |
| | | // .color(this,s.lastIndexOf(timeS),s.lastIndexOf(timeS)+it.laveTime.length,R.color.colorPrimary) |
| | | // .build() |
| | | showStateStr(it.servedMileage, it.servedTime) |
| | | if (it.lat.isNotEmpty()) |
| | | setRoute(it.lat.toDouble(), it.lon.toDouble(), order!!.endLat, order!!.endLon) |
| | | if (!it.orderPositionList.isNullOrEmpty()) { |
| | | val list = gson.fromJson<List<Point>>( |
| | | it.orderPositionList, |
| | | object : TypeToken<List<Point>>() {}.type |
| | | if (order?.orderType != 4) { // 非快件订单才显示订单状态 |
| | | tv_state.isVisible = true |
| | | val mile2 = "%.2f".format(it.servedMileage?.toDoubleOrNull() ?: 0.0) |
| | | val timeS = getString(R.string.多少分钟, it.laveTime) |
| | | val s = |
| | | getString(R.string.已服务时间, it.servedTime, mile2, it.laveMileage, timeS) |
| | | tv_state.text = SpanBuilder(s).color( |
| | | this, |
| | | s.indexOf(it.servedTime ?: ""), |
| | | s.indexOf(it.servedTime ?: "") + (it.servedTime ?: "").length, |
| | | R.color.colorPrimary |
| | | ) |
| | | if (list.isNotEmpty()) { |
| | | oldDrivedRouteOverlay = newDrivedRouteOverlay |
| | | newDrivedRouteOverlay = drawLine(list.map { LatLng(it.lat, it.lon) }) |
| | | oldDrivedRouteOverlay?.remove() |
| | | .color( |
| | | this, |
| | | s.indexOf(mile2), |
| | | s.indexOf(mile2) + mile2.length, |
| | | R.color.colorPrimary |
| | | ) |
| | | .color( |
| | | this, |
| | | s.indexOf(it.laveMileage ?: ""), |
| | | s.indexOf(it.laveMileage ?: "") + (it.laveMileage ?: "").length, |
| | | R.color.colorPrimary |
| | | ) |
| | | .color( |
| | | this, |
| | | s.lastIndexOf(timeS), |
| | | s.lastIndexOf(timeS) + (it.laveTime ?: "").length, |
| | | R.color.colorPrimary |
| | | ) |
| | | .build() |
| | | } |
| | | if (!it.orderPositionList.isNullOrEmpty()) { |
| | | try { |
| | | val list = gson.fromJson<List<Point>>( |
| | | it.orderPositionList, |
| | | object : TypeToken<List<Point>>() {}.type |
| | | ) |
| | | if (!list.isNullOrEmpty()) { |
| | | aMap?.also { it -> |
| | | oldDrivedRouteOverlay = newDrivedRouteOverlay |
| | | val data = list.map { LatLng(it.lat, it.lon) }.toMutableList() |
| | | if (driverMarker != null) { |
| | | data.add(driverMarker!!.position) |
| | | } |
| | | newDrivedRouteOverlay = AMapKit.drawLine(this, it, data, cn.sinata.xldutils.R.color.textColor99) |
| | | oldDrivedRouteOverlay?.remove() |
| | | } |
| | | } |
| | | } catch (e: Exception) { |
| | | e.printStackTrace() |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | private fun showStateStr(servedMileage: String, servedTime: String) { |
| | | val mile2 = "%.2f".format(servedMileage.toDouble()) |
| | | val timeS = getString(R.string.多少分钟, lastMin.toString()) |
| | | val laveMileage = "%.2f".format(lastDistance.toDouble() / 1000) |
| | | |
| | | val s = getString(R.string.已服务时间, servedTime, mile2, laveMileage, timeS) |
| | | tv_state.text = SpanBuilder(s).color( |
| | | this, |
| | | s.indexOf(servedTime), |
| | | s.indexOf(servedTime) + servedTime.length, |
| | | R.color.colorPrimary |
| | | ) |
| | | .color(this, s.indexOf(mile2), s.indexOf(mile2) + mile2.length, R.color.colorPrimary) |
| | | .color( |
| | | this, |
| | | s.indexOf(laveMileage), |
| | | s.indexOf(laveMileage) + laveMileage.length, |
| | | R.color.colorPrimary |
| | | ) |
| | | .color( |
| | | this, |
| | | s.lastIndexOf(timeS), |
| | | s.lastIndexOf(timeS) + lastMin.toString().length, |
| | | R.color.colorPrimary |
| | | ) |
| | | .build() |
| | | } |
| | | |
| | | private var startMarker: Marker? = null |
| | | private var endMarker: Marker? = null |
| | | var markerLine: Polyline? = null |
| | | |
| | | /** |
| | | * @param isStart true:起点标记 false:终点标记 |
| | | */ |
| | | private fun setMarker(latLon: LatLng, content: CharSequence = "", isStart: Boolean = true) { |
| | | val language = SPUtils.instance().getString("language", "en") |
| | | val language = LanguageUtil.getLanguage() |
| | | if (isStart) { |
| | | val ic = when (language) { |
| | | "en" -> R.mipmap.starting_point_e |
| | | "ch" -> R.mipmap.starting_point |
| | | Const.Language.ENGLISH -> R.mipmap.starting_point_e |
| | | Const.Language.CHINESE -> R.mipmap.starting_point |
| | | else -> R.mipmap.starting_point_f |
| | | } |
| | | val icon = if (content.isEmpty()) BitmapDescriptorFactory.fromResource(ic) |
| | |
| | | view.find<TextView>(R.id.tv_content).text = content |
| | | view.find<ImageView>(R.id.iv).imageResource = |
| | | if (order?.state == 1) R.mipmap.icon_location else ic |
| | | BitmapDescriptorFactory.fromBitmap(convertViewToBitmap(view)!!) |
| | | BitmapDescriptorFactory.fromBitmap(convertViewToBitmap(view)) |
| | | } |
| | | if (startMarker != null) { |
| | | startMarker!!.position = latLon |
| | |
| | | } else { |
| | | val options = MarkerOptions() |
| | | options.position(latLon).icon(icon) |
| | | startMarker = aMap.addMarker(options) |
| | | startMarker = aMap?.addMarker(options) |
| | | } |
| | | } else { |
| | | val ic = when (language) { |
| | | "en" -> R.mipmap.end_point_e |
| | | "ch" -> R.mipmap.end_point |
| | | Const.Language.ENGLISH -> R.mipmap.end_point_e |
| | | Const.Language.CHINESE -> R.mipmap.end_point |
| | | else -> R.mipmap.end_point_f |
| | | } |
| | | if (endMarker != null) { |
| | |
| | | } else { |
| | | val options = MarkerOptions() |
| | | options.position(latLon).icon(BitmapDescriptorFactory.fromResource(ic)) |
| | | endMarker = aMap.addMarker(options) |
| | | endMarker = aMap?.addMarker(options) |
| | | } |
| | | } |
| | | } |
| | | |
| | | private var driverMarker: Marker? = null //司机标记 |
| | | private fun setDriverMarker(latLng: LatLng) { //现在使用谷歌套餐,不需要自己画司机位置 |
| | | // if (driverMarker == null) { |
| | | // val b = BitmapDescriptorFactory.fromResource(R.mipmap.location_car) |
| | | // val options = MarkerOptions() |
| | | // options.position(latLng) |
| | | // options.icon(b) |
| | | // driverMarker = aMap.addMarker(options) |
| | | // } else { |
| | | // driverMarker?.position = latLng |
| | | // } |
| | | } |
| | | |
| | | private var oldDrivingRouteOverlay: Polyline? = null |
| | | private var newDrivingRouteOverlay: Polyline? = null |
| | | private var routeSearchDisposable: DisposableSubscriber<RouteBean>? = null |
| | | |
| | | private var lastMoveTime = 0L |
| | | |
| | | /** |
| | | * 废弃 |
| | | * 现在使用谷歌乘客sdk,不再自己计算路径 |
| | | */ |
| | | private fun setRoute(startLat: Double, startLon: Double, endLat: Double, endLon: Double) { |
| | | //如果上一次还没处理完,取消订阅 |
| | | // if (routeSearchDisposable != null && !routeSearchDisposable!!.isDisposed) { |
| | | // routeSearchDisposable?.dispose() |
| | | // } |
| | | // routeSearchDisposable = object : DisposableSubscriber<RouteBean>() { |
| | | // override fun onComplete() { |
| | | // } |
| | | // |
| | | // override fun onNext(t: RouteBean?) { |
| | | // if (t?.status == "OK") { |
| | | // oldDrivingRouteOverlay = newDrivingRouteOverlay |
| | | // val geodesic = PolylineOptions() |
| | | // .add(LatLng(startLat, startLon)) |
| | | // .width(20f) |
| | | // .color(Color.parseColor("#00C47A")) |
| | | // .geodesic(true) |
| | | // t.routes.firstOrNull()?.legs?.firstOrNull()?.steps?.forEach { |
| | | // geodesic.add(LatLng(it.end_location.lat, it.end_location.lng)) |
| | | // } |
| | | // geodesic.add(LatLng(endLat,endLon)) |
| | | // newDrivingRouteOverlay = aMap.addPolyline(geodesic) |
| | | // oldDrivingRouteOverlay?.remove() |
| | | // |
| | | // if (System.currentTimeMillis() - lastMoveTime > 10000L){ |
| | | // lastMoveTime = System.currentTimeMillis() |
| | | // aMap.animateCamera(CameraUpdateFactory.newLatLngBounds( |
| | | // LatLngBounds(LatLng(t.routes.firstOrNull()?.bounds?.southwest?.lat?:0.0,t.routes.firstOrNull()?.bounds?.southwest?.lng?:0.0), |
| | | // LatLng(t.routes.firstOrNull()?.bounds?.northeast?.lat?:0.0,t.routes.firstOrNull()?.bounds?.northeast?.lng?:0.0)),280)) |
| | | // } |
| | | // } |
| | | // } |
| | | // |
| | | // override fun onError(t: Throwable?) { |
| | | // Log.e("Trip","路径规划失败") |
| | | // } |
| | | // } |
| | | // HttpManager.directions(startLat, startLon, endLat, endLon).defaultScheduler().subscribe(routeSearchDisposable) |
| | | } |
| | | |
| | | /** |
| | | * 绘制已行驶灰色路径 |
| | | */ |
| | | private fun drawLine(latLngs: List<LatLng?>): Polyline? { |
| | | val options = PolylineOptions().addAll(latLngs) |
| | | if (driverMarker != null) { |
| | | options.add(driverMarker!!.position) |
| | | if (driverMarker == null) { |
| | | val b = BitmapDescriptorFactory.fromResource(R.mipmap.location_car) |
| | | val options = MarkerOptions() |
| | | options.position(latLng) |
| | | options.icon(b) |
| | | driverMarker = aMap?.addMarker(options) |
| | | } else { |
| | | driverMarker?.position = latLng |
| | | } |
| | | options.width(20f) |
| | | .color(Color.parseColor("#999999")) |
| | | return aMap.addPolyline(options) |
| | | } |
| | | |
| | | /** |
| | |
| | | override fun handleMessage(msg: Message): Boolean { |
| | | if (order == null) |
| | | return true |
| | | when (msg?.what) { |
| | | when (msg.what) { |
| | | 0 -> { |
| | | if (order?.state == 1) { |
| | | val latLon = LatLng(order!!.startLat, order!!.startLon) |
| | | val waittime = order!!.insertTime.parserTime() |
| | | val s = System.currentTimeMillis() |
| | | val i = Math.max(s - waittime, 0L) |
| | | val i = (s - waittime).coerceAtLeast(0L) |
| | | val c = getString(R.string.正在寻找车辆, i / 1000 / 60, i / 1000 % 60) |
| | | setMarker( |
| | | latLon, SpanBuilder(c) |
| | | .color(this, c.length - 6, c.length, R.color.colorRed).build() |
| | | latLon, |
| | | SpanBuilder(c).color(this, c.length - 6, c.length, R.color.colorRed).build() |
| | | ) |
| | | IGoApplication.intervalCount++ |
| | | if (IGoApplication.intervalCount > 7) { |
| | | queryEndPush() |
| | | getTrippingData() |
| | | } |
| | | Log.e("timer", "事件0:" + IGoApplication.intervalCount) |
| | | handler.sendEmptyMessageDelayed(0, 1000) |
| | | } |
| | | } |
| | |
| | | if (IGoApplication.intervalCount > 7) { |
| | | getTrippingData() |
| | | } |
| | | Log.e("timer", "事件1:" + IGoApplication.intervalCount) |
| | | handler.sendEmptyMessageDelayed(1, 1000) |
| | | } |
| | | } |
| | |
| | | if (IGoApplication.intervalCount > 7) { |
| | | getTrippingData() |
| | | } |
| | | Log.e("timer", "事件2:" + IGoApplication.intervalCount) |
| | | if (order?.state == 2) |
| | | fl_reserve.visibility = |
| | | if (order!!.travelTime1.isNotEmpty() && order!!.travelTime1.parserTime() - System.currentTimeMillis() > (30L * 60 * 1000)) View.VISIBLE else View.GONE |
| | |
| | | return true |
| | | } |
| | | |
| | | override fun onStateChanged(id: Int, state: Int) { //state |
| | | if (id == order?.orderId) { |
| | | setResult(Activity.RESULT_OK) |
| | | override fun onStateChanged(id: Int, type: Int, state: Int) { //state |
| | | if (id == order?.orderId && type == order?.orderType) { |
| | | setResult(RESULT_OK) |
| | | if (order?.driverId == 0 || order?.arriveTime.isNullOrEmpty() || state == 15 || state == 10) { //司机接单和到达预约点需要掉接口去获取司机信息以及等待开始时间 |
| | | getData() |
| | | } else { |
| | |
| | | } |
| | | |
| | | override fun onTrippingChanged(info: TrippingInfo) { |
| | | if (info.orderId == order?.orderId) { |
| | | if (info.orderId == order?.orderId && info.orderType == order?.orderType) { |
| | | setTrippingUI(info) |
| | | } |
| | | } |
| | | |
| | | override fun onAddressChanged(info: TrippingInfo) { |
| | | Log.e("地址变更: ", (info.status == 2).toString()) |
| | | if (info.orderId == order?.orderId) { |
| | | if (info.orderId == order?.orderId && info.orderType == order?.orderType) { |
| | | if (info.status == 2) { //司机同意修改目的地 |
| | | LogHelper.logRecord("司机同意修改目的地:orderId:${id} orderType:${type}") |
| | | getData() |
| | | } |
| | | if (info.status == 3) {//司机拒绝修改目的地 |
| | | LogHelper.logRecord("司机拒绝修改目的地:orderId:${id} orderType:${type}") |
| | | val tipDialog = TipDialog() |
| | | tipDialog.arguments = bundleOf( |
| | | "msg" to getString(R.string.拒绝变更), |
| | |
| | | } |
| | | |
| | | override fun onShuttleConfirm(id: Int, type: Int) { |
| | | if (this.type == Const.OrderType.TYPE_SPECIAL && order?.state == 1) { |
| | | if (this.type == TYPE_SPECIAL && order?.state == 1) { |
| | | this.type = type |
| | | this.id = id |
| | | getData() |
| | |
| | | |
| | | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { |
| | | super.onActivityResult(requestCode, resultCode, data) |
| | | if (resultCode == Activity.RESULT_OK && data != null) { |
| | | if (resultCode == RESULT_OK && data != null) { |
| | | if (requestCode == 1) { |
| | | setResult(Activity.RESULT_OK) |
| | | setResult(RESULT_OK) |
| | | finish() |
| | | val money = data.getDoubleExtra("money", 0.0) |
| | | if (money != 0.0) |
| | | startActivity<OrderDetailActivity>("id" to id, "type" to type) |
| | | } else if (requestCode == 2) { //修改终点 |
| | | LogHelper.logRecord("乘客变更目的地:orderId:${id} orderType:${type}") |
| | | val lat = data.getDoubleExtra("lat", 0.0) |
| | | val lon = data.getDoubleExtra("lon", 0.0) |
| | | val address = data.getStringExtra("name") ?: "" |
| | |
| | | override fun onOk() { |
| | | showDialog() |
| | | HttpManager.updateEndAddress(address, lat, lon, id, type) |
| | | .request(this@TripActivity) { _, _ -> |
| | | .request(this@TripActivity, success = { _, _ -> |
| | | LogHelper.logRecord("乘客变更目的地成功:orderId:${id} orderType:${type}") |
| | | }) { code, msg -> |
| | | LogHelper.logRecord("乘客变更目的地失败:orderId:${id} orderType:${type} code:${code} msg:${msg}") |
| | | } |
| | | } |
| | | |
| | |
| | | * @param view |
| | | * @return |
| | | */ |
| | | fun convertViewToBitmap(view: View): Bitmap? { |
| | | fun convertViewToBitmap(view: View): Bitmap { |
| | | view.isDrawingCacheEnabled = true |
| | | view.measure( |
| | | View.MeasureSpec.makeMeasureSpec( |
| | |
| | | IGoApplication.tripId = "" |
| | | session?.stop() |
| | | super.onDestroy() |
| | | } |
| | | |
| | | override fun onResult(p0: SHARE_MEDIA?) { |
| | | } |
| | | |
| | | override fun onCancel(p0: SHARE_MEDIA?) { |
| | | } |
| | | |
| | | override fun onError(p0: SHARE_MEDIA?, p1: Throwable?) { |
| | | } |
| | | |
| | | override fun onStart(p0: SHARE_MEDIA?) { |
| | | } |
| | | |
| | | override fun onBackPressed() { |