| | |
| | | import androidx.appcompat.widget.AppCompatTextView |
| | | import androidx.core.content.ContextCompat |
| | | import androidx.core.os.bundleOf |
| | | import androidx.core.view.isVisible |
| | | import androidx.recyclerview.widget.LinearLayoutManager |
| | | import androidx.recyclerview.widget.RecyclerView |
| | | import cn.sinata.rxnetty.LogHelper.logRecord |
| | | import cn.sinata.rxnetty.NettyClient |
| | | import cn.sinata.xldutils.activity.BaseActivity |
| | | import cn.sinata.xldutils.callPhone |
| | |
| | | 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 org.jetbrains.anko.dip |
| | | import org.jetbrains.anko.find |
| | |
| | | |
| | | class TripActivity : BaseActivity(), Handler.Callback, OrderStateChangeListener, UMShareListener { |
| | | lateinit var aMap: ConsumerGoogleMap |
| | | private val TAG = "TripActivity" |
| | | |
| | | override fun onCreate(savedInstanceState: Bundle?) { |
| | | super.onCreate(savedInstanceState) |
| | |
| | | } //客户反馈:快件单一旦司机开始行程后(取到快件送货途中)就不能再取消订单 |
| | | titleBar.getRightButton(0)?.gone() |
| | | aMap.isMyLocationEnabled = false //行程中取消乘客定位 |
| | | drawLine() |
| | | } |
| | | |
| | | 10 -> { |
| | |
| | | } |
| | | } |
| | | |
| | | private fun drawLine() { |
| | | if (order?.orderType == 4) return // 快件订单不绘制 |
| | | if (startMarker != null && endMarker != null) { |
| | | AMapKit.initRouteLine( |
| | | // this, |
| | | startMarker!!.position, |
| | | endMarker!!.position, |
| | | object : (MutableList<LatLng>, Float, Long) -> Unit { |
| | | override fun invoke(p1: MutableList<LatLng>, p2: Float, p3: Long) { |
| | | markerLine?.remove() |
| | | markerLine = AMapKit.drawLine(this@TripActivity, aMap, p1) |
| | | AMapKit.moveCamera(aMap, startMarker!!.position, endMarker!!.position) |
| | | } |
| | | }) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取行程中的数据:主要是司机位置,订单状态变化,距离、时间等预算信息 |
| | |
| | | * 行程中的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 (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.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() |
| | | } |
| | | } |
| | | |
| | | logRecord(TAG,"setTrippingUI tips ${tv_state.text}") |
| | | |
| | | if (it.lat.isNotEmpty()) { |
| | | //todo 移动视角吗?不需要,因为查询路径后做了移动 |
| | |
| | | } |
| | | |
| | | 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 (order?.orderType != 4) { // 非快件订单才显示订单状态 |
| | | tv_state.isVisible = true |
| | | 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) |
| | | logRecord(TAG,"setTrippingUI tips ${tv_state.text}") |
| | | } |
| | | if (it.lat.isNotEmpty()) |
| | | setRoute(it.lat.toDouble(), it.lon.toDouble(), order!!.endLat, order!!.endLon) |
| | | if (!it.orderPositionList.isNullOrEmpty()) { |
| | |
| | | |
| | | private var startMarker: Marker? = null |
| | | private var endMarker: Marker? = null |
| | | var markerLine: Polyline? = null |
| | | |
| | | /** |
| | | * @param isStart true:起点标记 false:终点标记 |
| | |
| | | |
| | | 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 |
| | | // } |
| | | 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 |
| | |
| | | } |
| | | |
| | | override fun onTrippingChanged(info: TrippingInfo) { |
| | | logRecord(TAG,"onTrippingChanged order info ${Gson().toJson(order)}") |
| | | logRecord(TAG,"onTrippingChanged socket msg ${Gson().toJson(info)}") |
| | | if (info.orderId == order?.orderId) { |
| | | setTrippingUI(info) |
| | | } |