| | |
| | | import android.os.CountDownTimer |
| | | import android.os.Handler |
| | | import android.os.Looper |
| | | import android.util.Log |
| | | import android.view.Gravity |
| | | import android.view.View |
| | | import cn.sinata.xldutils.utils.* |
| | | import com.amap.api.location.AMapLocationListener |
| | | import com.amap.api.maps.AMap |
| | | import com.amap.api.maps.AMapUtils |
| | | import com.amap.api.maps.model.LatLng |
| | | import com.amap.api.maps.model.Marker |
| | | import com.amap.api.maps.model.Polyline |
| | |
| | | import io.reactivex.android.schedulers.AndroidSchedulers |
| | | import io.reactivex.disposables.Disposable |
| | | import io.reactivex.schedulers.Schedulers |
| | | import kotlinx.android.synthetic.main.activity_change_one.* |
| | | import kotlinx.android.synthetic.main.activity_select_start_point.* |
| | | import kotlinx.android.synthetic.main.activity_trip.* |
| | | import kotlinx.android.synthetic.main.activity_trip.map_view |
| | |
| | | |
| | | |
| | | class TripActivity : MyBaseActivity() { |
| | | |
| | | /*** |
| | | * // 流程操作状态(3=开始出发预约点,4=到达预约点,5=开始服务,6=服务结束) |
| | | * 页面一共4个marker 1:预约地点 2:起点 3终点 4:司机点 |
| | |
| | | var markerLine: Polyline? = null |
| | | lateinit var aMap: AMap |
| | | lateinit var orderBean: OrderBean |
| | | |
| | | var autoExitNavi = false //是否自动退出过,只自动退出一次即可 |
| | | |
| | | private val rxPermissions by lazy { |
| | | RxPermissions(this) |
| | |
| | | MyApplication.addOrderView(object : MyApplication.OrderStatueView { |
| | | override fun orderInfo(data: OrderSimpleData?) { |
| | | data?.let { |
| | | when(it.orderType){ |
| | | 1,2,3 -> { |
| | | if (it.status == 10 || it.status == 12) { |
| | | when (it.orderType) { |
| | | 1, 2, 3,7 -> { |
| | | if ((it.status == 10 || it.status == 12)&&MyApplication.currentOrderId.isNotEmpty()&&it.orderId.toString() == orderId) { |
| | | Handler(Looper.getMainLooper()).post { |
| | | toast("用户已取消订单") |
| | | MyApplication.getTTsManager().setVideoText("用户已取消订单") |
| | |
| | | orderSimpleData?.let { |
| | | if (it.status == 10 || it.status == 12) { |
| | | Handler(Looper.getMainLooper()).post { |
| | | toast("用户已取消订单") |
| | | // toast("用户已取消订单") |
| | | MyApplication.getTTsManager().setVideoText("用户已取消订单") |
| | | MyApplication.currentOrderType = "" |
| | | MyApplication.currentOrderId = "" |
| | |
| | | "orderType" to orderType |
| | | ) |
| | | } else { |
| | | DialogUtil.getDelAndSureDialog( |
| | | val d = DialogUtil.getDelAndSureDialog( |
| | | this, |
| | | "现在改派将收取" + data.data.amount + "元改派费,您是否要进行改派?", |
| | | {}, |
| | |
| | | "money" to data.data.amount.toString() |
| | | ) |
| | | }) |
| | | val view = DialogUtil.getView(d) |
| | | view.tv_view_two_base.gravity = Gravity.CENTER |
| | | } |
| | | |
| | | |
| | | } |
| | | } |
| | | iv_move.setOnClickListener { |
| | |
| | | moveCamera(aMap, carMarker!!.position) |
| | | } |
| | | 5, 6 -> { |
| | | if (endMarker == null){ |
| | | if (endMarker == null) { |
| | | moveCamera(aMap, carMarker!!.position) |
| | | }else{ |
| | | } else { |
| | | moveCamera(aMap, carMarker!!.position, endMarker!!.position) |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | 5, 6 -> { |
| | | if (endMarker == null){ |
| | | if (endMarker == null) { |
| | | toast("暂无终点") |
| | | }else{ |
| | | } else { |
| | | startActivity<GPSNaviActivity>( |
| | | "start" to carMarker!!.position, |
| | | "end" to endMarker!!.position |
| | |
| | | toast("只能在预约时间的半小时内出行") |
| | | return@let |
| | | } |
| | | if (it.data.orderState == 4&& !rxPermissions.isGranted(Manifest.permission.RECORD_AUDIO)&& !rxPermissions.isGranted(Manifest.permission.WRITE_EXTERNAL_STORAGE)){ |
| | | if (it.data.orderState == 4&& (!rxPermissions.isGranted(Manifest.permission.RECORD_AUDIO) || !rxPermissions.isGranted(Manifest.permission.WRITE_EXTERNAL_STORAGE))){ |
| | | DialogUtil.getDelAndSureDialog(this,"去授权","取消","根据平台规则,为了保证司乘安全,我们将会对行程进行录音,因此需要获取录音和文件存储权限",{ |
| | | }){ |
| | | rxPermissions.request(Manifest.permission.RECORD_AUDIO,Manifest.permission.WRITE_EXTERNAL_STORAGE).subscribe { |
| | | if (it){ |
| | | |
| | | }else{ |
| | | } else { |
| | | toast("请前往应用设置页面打开录音和文件存储权限") |
| | | } |
| | | } |
| | |
| | | return@let |
| | | } |
| | | if (it.data.endAddress.isNullOrEmpty()&&it.data.orderState == 4){ |
| | | DialogUtil.getDelAndSureDialog(this,"去填写","取消","乘客未填写目的地,请代乘客填写目的地后开始行程",{ |
| | | }){ |
| | | val delAndSureDialog = DialogUtil.getDelAndSureDialog( |
| | | this, |
| | | "去填写", |
| | | "取消", |
| | | "乘客未填写目的地,请代乘客填写目的地后开始行程", |
| | | { |
| | | }) { |
| | | byChangeEnd = true |
| | | startActivity<SearchSiteActivity>("currentCityName" to (MyApplication.aMapLocation?.city?:""),"type" to "3") |
| | | startActivity<SearchSiteActivity>( |
| | | "currentCityName" to (MyApplication.aMapLocation?.city ?: ""), |
| | | "type" to "3" |
| | | ) |
| | | } |
| | | val view = DialogUtil.getView(delAndSureDialog) |
| | | view.tv_view_two_base.gravity = Gravity.CENTER |
| | | return@let |
| | | } |
| | | it.data.orderState++ |
| | | callStatue(it.data.orderState,{ |
| | | callStatue(it.data.orderState, { |
| | | showStatueMapUI(it) |
| | | if (it.data.orderState == 5){ |
| | | if (it.data.orderState == 5) { |
| | | showRecordDialog() |
| | | } |
| | | }) { |
| | |
| | | } |
| | | 5, 6 -> { |
| | | it.data.orderState = 6 |
| | | when(orderType){ |
| | | when (orderType) { |
| | | "2" -> { |
| | | showMoneyTypeDialog() |
| | | } |
| | | "1" -> { |
| | | callStatue(6,{ |
| | | "1","7" -> { |
| | | callStatue(6, { |
| | | startActivity<MajorSureMoneyActivity>( |
| | | "orderId" to orderId, |
| | | "orderType" to orderType |
| | |
| | | view.tv_view_two_base.gravity = Gravity.CENTER |
| | | view.view_hint_close_base.visibility = View.INVISIBLE |
| | | view.tv_count_timer.visible() |
| | | val timer = object:CountDownTimer(3000,1000){ |
| | | val timer = object:CountDownTimer(3000, 1000){ |
| | | override fun onTick(millisUntilFinished: Long) { |
| | | view.tv_count_timer.text = "${(millisUntilFinished/1000)+1}S" |
| | | } |
| | |
| | | onlySureDialog.setOnDismissListener { |
| | | timer.cancel() |
| | | } |
| | | EventBus.getDefault().post(BaseEvent(BaseEvent.START_RECORD)) |
| | | } |
| | | |
| | | private fun callStatue(i: Int, click: () -> Unit, clickFail: () -> Unit) { |
| | |
| | | map["state"] = i |
| | | map["lat"] = MyApplication.getLocation().latitude |
| | | map["lon"] = MyApplication.getLocation().longitude |
| | | callNet(Api.process, map,{ |
| | | callNet(Api.process, map, { |
| | | click() |
| | | }) { |
| | | clickFail() |
| | |
| | | pop.contentView.tv_ok.setOnClickListener { |
| | | pop.dismiss() |
| | | if (payType == 1) { |
| | | callStatue(6,{ |
| | | callStatue(6, { |
| | | startActivity<FillOutActivity>("orderId" to orderId, "orderType" to orderType) |
| | | finish() |
| | | }) { |
| | |
| | | map["orderId"] = orderId |
| | | map["orderType"] = orderType |
| | | map["type"] = payType |
| | | callStatue(6,{ |
| | | callStatue(6, { |
| | | callNet(Api.confirmFees, map) { |
| | | finish() |
| | | startActivity<OrderOverActivity>( |
| | |
| | | changeCarFive(false) |
| | | } |
| | | } |
| | | if (it.data.orderState == 3){ |
| | | val calculateLineDistance = AMapUtils.calculateLineDistance( |
| | | carMarker!!.position, |
| | | LatLng(it.data.startLat, it.data.startLon) |
| | | ) |
| | | if (calculateLineDistance<80&&!autoExitNavi){ |
| | | EventBus.getDefault().post(BaseEvent(BaseEvent.EXIT_NAVI)) |
| | | } |
| | | } |
| | | } |
| | | }) |
| | | } |
| | | |
| | | private fun changeCarThree(isMove: Boolean) { |
| | | if (makeMarker != null && carMarker != null) { |
| | | AMapKit.initRouteLine( |
| | | this, |
| | | makeMarker!!.position, |
| | | carMarker!!.position, |
| | | object : (MutableList<LatLng>, Float, Long) -> Unit { |
| | | override fun invoke(p1: MutableList<LatLng>, p2: Float, p3: Long) { |
| | | var view = creatCarView("距预约点" + AMapKit.getTance(p2)) |
| | | carMarker!!.setIcon(getIcon(view)) |
| | | addline(p1) |
| | | if (isMove) |
| | | moveCamera(aMap, makeMarker!!.position, carMarker!!.position) |
| | | } |
| | | }) |
| | | val calculateLineDistance = AMapUtils.calculateLineDistance(makeMarker!!.position, carMarker!!.position) |
| | | Log.e("mmp","两点直线距离:${calculateLineDistance}m") |
| | | if (calculateLineDistance>100) //大于100米才规划路径 |
| | | AMapKit.initRouteLine( |
| | | this, |
| | | makeMarker!!.position, |
| | | carMarker!!.position, |
| | | object : (MutableList<LatLng>, Float, Long) -> Unit { |
| | | override fun invoke(p1: MutableList<LatLng>, p2: Float, p3: Long) { |
| | | var view = creatCarView("距预约点" + AMapKit.getTance(p2)) |
| | | carMarker!!.setIcon(getIcon(view)) |
| | | addline(p1) |
| | | if (isMove) |
| | | moveCamera(aMap, makeMarker!!.position, carMarker!!.position) |
| | | } |
| | | }) |
| | | else{ |
| | | var view = creatCarView("距预约点" + AMapKit.getTance(calculateLineDistance)) |
| | | carMarker!!.setIcon(getIcon(view)) |
| | | if (isMove) |
| | | moveCamera(aMap, makeMarker!!.position, carMarker!!.position) |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | private fun callOrder() { |
| | | MyApplication.currentOrderId = orderId |
| | | MyApplication.currentOrderType = orderType |
| | | MyApplication.recordOrderId = orderId |
| | | MyApplication.recordOrderType = orderType |
| | | var map = getMapByAny() |
| | | map["orderId"] = orderId |
| | | map["orderType"] = orderType |
| | |
| | | private fun showUi(orderBean: OrderBean?) { |
| | | orderBean?.let { |
| | | tv_name.text = orderBean.data.nickName |
| | | tv_passenger_phone.text = orderBean.data.phone |
| | | tv_car_num.text = it.data.historyNum.toString() + "次乘车" |
| | | tv_time.text = it.data.travelTime_ |
| | | tv_start_address.text = it.data.startAddress |
| | |
| | | tv_end_address.text = it.data.endAddress |
| | | tv_change_end.gone() |
| | | } |
| | | if (orderType == "1"){ |
| | | if (orderType == "1"||orderType == "7"){ |
| | | tv_red_money.gone() |
| | | } |
| | | tv_red_money.text = it.data.tipMoney.toString() + "元红包" |
| | |
| | | view.iv_img.setImageResource(R.mipmap.end_point) |
| | | endMarker = addMarker(aMap, it.data.endLat, it.data.endLon, view, "") |
| | | }else if (endMarker?.position?.latitude == 0.0){ |
| | | endMarker?.position = LatLng(orderBean.data.endLat,orderBean.data.endLon) |
| | | endMarker?.position = LatLng(orderBean.data.endLat, orderBean.data.endLon) |
| | | } |
| | | endMarker?.isVisible = false |
| | | if (carMarker == null) { |
| | |
| | | val carView = createView(R.layout.item_map_market, this) |
| | | carView.iv_img.setImageResource(R.mipmap.car_trip) |
| | | carView.tv_hint.visible() |
| | | carView.tv_hint.setColorBuild(this,content,R.color.main_yellow_qia,4,content.length) |
| | | carView.tv_hint.setColorBuild(this, content, R.color.main_yellow_qia, 4, content.length) |
| | | return carView |
| | | } |
| | | |
| | |
| | | tv_Right.visible() |
| | | when (it.data.orderState) { |
| | | 2, 3 -> { |
| | | if (it.data.reassign == 1){ |
| | | if (it.data.reassign == 1) { |
| | | tv_Right.gone() |
| | | } |
| | | iv_to_gd.visible() |
| | |
| | | } |
| | | 4 -> { |
| | | iv_to_gd.gone() |
| | | if (it.data.reassign == 1){ |
| | | if (it.data.reassign == 1) { |
| | | tv_Right.gone() |
| | | } |
| | | closeLine() |
| | |
| | | carMarker?.isVisible = true |
| | | changeCarFive(true) |
| | | setTitleText("服务中") |
| | | slide_btn.changeButtonText("送达该乘客") |
| | | slide_btn.changeButtonText("乘客已到达") |
| | | if (!MyApplication.isRecording){ |
| | | EventBus.getDefault().post(BaseEvent(BaseEvent.START_RECORD)) |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | handler?.removeCallbacksAndMessages(null) |
| | | } |
| | | closeTimeStart() |
| | | map_view.onDestroy() |
| | | } |
| | | |
| | | override fun onPause() { |
| | | super.onPause() |
| | | map_view.onPause() |
| | | } |
| | | |
| | | override fun onLowMemory() { |
| | | super.onLowMemory() |
| | | map_view.onLowMemory() |
| | | } |
| | | |
| | | override fun onResume() { |
| | | super.onResume() |
| | | map_view.onResume() |
| | | } |
| | | |
| | | private fun addline(allLine: MutableList<LatLng>) { |
| | | closeLine() |
| | |
| | | mapByAny["lon"] = lon |
| | | mapByAny["endAddress"] = name |
| | | mapByAny["orderId"] = orderId |
| | | callNet(Api.setEnd,mapByAny){ |
| | | callNet(Api.setEnd, mapByAny) { |
| | | orderBean.data.endAddress = name |
| | | orderBean.data.endLat = lat |
| | | orderBean.data.endLon = lon |
| | | tv_end_address.text = name |
| | | tv_change_end.gone() |
| | | if (byChangeEnd){ |
| | | if (byChangeEnd) { |
| | | orderBean.data.orderState++ |
| | | callStatue(orderBean.data.orderState,{ |
| | | showStatueMapUI(orderBean) |
| | | callStatue(orderBean.data.orderState, { |
| | | showRecordDialog() |
| | | showStatueMapUI(orderBean) |
| | | }) { |
| | | orderBean.data.orderState-- |
| | | } |