package com.driver.igotrip.ui.main.small_cargo
|
|
import android.annotation.SuppressLint
|
import android.os.Bundle
|
import android.os.Handler
|
import android.os.Looper
|
import android.util.Log
|
import android.util.TypedValue
|
import android.view.View
|
import android.widget.EditText
|
import android.widget.ImageView
|
import android.widget.TextView
|
import cn.sinata.xldutils.utils.*
|
import com.google.android.gms.maps.model.LatLng
|
import com.google.android.gms.maps.model.Marker
|
import com.driver.igotrip.R
|
import com.driver.igotrip.base.BaseEvent
|
import com.driver.igotrip.base.MyApplication
|
import com.driver.igotrip.base.MyBaseActivity
|
import com.driver.igotrip.base.OrderTimeOutManager
|
import com.driver.igotrip.base.gaode.AMapKit
|
import com.driver.igotrip.base.gaode.AMapKit.addMarker
|
import com.driver.igotrip.base.gaode.AMapKit.getIcon
|
import com.driver.igotrip.base.gaode.AMapKit.getTimeType
|
import com.driver.igotrip.base.gaode.AMapKit.initMap
|
import com.driver.igotrip.base.gaode.AMapKit.moveCamera
|
import com.driver.igotrip.bean.*
|
import com.driver.igotrip.netUtls.*
|
import com.driver.igotrip.ui.DialogUtil
|
import com.driver.igotrip.ui.UiUtil
|
import com.driver.igotrip.ui.main.ReassignActivity
|
import com.driver.igotrip.ui.main.major.MajorSureMoneyActivity
|
import com.driver.igotrip.utils.DateUtil
|
import com.driver.igotrip.utils.MyUtils
|
import com.driver.igotrip.utils.view.SlidingButton
|
import com.google.android.gms.maps.GoogleMap
|
import com.google.android.gms.maps.SupportMapFragment
|
import com.google.android.gms.maps.model.Polyline
|
import com.google.gson.Gson
|
import com.trello.rxlifecycle3.android.ActivityEvent
|
import io.reactivex.Observable
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
import io.reactivex.disposables.Disposable
|
import io.reactivex.schedulers.Schedulers
|
|
import org.greenrobot.eventbus.EventBus
|
import org.jetbrains.anko.find
|
import org.jetbrains.anko.startActivity
|
import org.jetbrains.anko.toast
|
import java.util.concurrent.TimeUnit
|
|
|
class SmallCargoActivity : MyBaseActivity() {
|
/***
|
* 1=待接单,2=待出发,3=待到达预约地点,4=待取货,5=送货中,6=已送达,7=待支付,8=需补差价,9=已取货,10=已取消,11=改派中,12=已支付差价
|
|
integer($int32)
|
订单状态(1=待接单,2=待出发,3=待到达预约地点,4=待乘客上车,5=服务中,6=完成服务,7=待支付,8=待评价,9=已完成,10=已取消,11=改派中,12=取消待支付)
|
*/
|
|
/***
|
* // 流程操作状态(3=开始出发预约点,4=到达预约点,5=开始服务,6=服务结束)
|
* 页面一共4个marker 1:预约地点 2:起点 3终点 4:司机点
|
*/
|
val orderType by lazy {
|
intent.getStringExtra("orderType") ?: ""
|
}
|
|
val orderId by lazy {
|
intent.getStringExtra("orderId") ?: ""
|
}
|
var isTimeStart = false //限制计时器
|
|
var makeMarker: Marker? = null
|
var startMarker: Marker? = null
|
var endMarker: Marker? = null
|
var carMarker: Marker? = null
|
var markerLine: Polyline? = null
|
var mapInitStatus = false // 地图初始化状态
|
lateinit var aMap: GoogleMap
|
var orderBean: OrderBean? = null
|
var graylist = arrayListOf<LatLng>() // 灰色轨迹
|
var grayline: Polyline? = null
|
|
private val tv_name by lazy { find<TextView>(R.id.tv_name) }
|
private val tv_car_num by lazy { find<TextView>(R.id.tv_car_num) }
|
private val tv_people_cargo by lazy { find<TextView>(R.id.tv_people_cargo) }
|
private val tv_remark by lazy { find<TextView>(R.id.tv_remark) }
|
private val tv_money_cargo by lazy { find<TextView>(R.id.tv_money_cargo) }
|
private val tv_time by lazy { find<TextView>(R.id.tv_time) }
|
private val tv_start_address by lazy { find<TextView>(R.id.tv_start_address) }
|
private val tv_end_address by lazy { find<TextView>(R.id.tv_end_address) }
|
private val tv_gap_money by lazy { find<TextView>(R.id.tv_gap_money) }
|
private val btn_gap_money by lazy { find<TextView>(R.id.btn_gap_money) }
|
private val iv_move by lazy { find<View>(R.id.iv_move) }
|
private val iv_phone by lazy { find<View>(R.id.iv_phone) }
|
private val iv_police by lazy { find<View>(R.id.iv_police) }
|
private val iv_to_gd by lazy { find<View>(R.id.iv_to_gd) }
|
private val slide_btn by lazy { find<SlidingButton>(R.id.slide_btn) }
|
|
override fun setContentView() {
|
setContentView(R.layout.activity_trip_cargo)
|
}
|
|
fun initView2() {
|
setTitleText("")
|
tv_Right.text = getString(R.string.申请改派短)
|
callOrder() {
|
initMineLocation()
|
}
|
onclick()
|
addSockectCancel()
|
|
var language = SPUtils.getString("language")
|
if (language.isEmpty()){
|
language = "en"
|
}
|
if (language == "en" || language == "fr")
|
btn_gap_money.setTextSize(TypedValue.COMPLEX_UNIT_SP,12f)
|
else
|
btn_gap_money.setTextSize(TypedValue.COMPLEX_UNIT_SP,14f)
|
}
|
|
override fun initView() {
|
|
}
|
|
private fun addSockectCancel() {
|
checkOrderStatue()
|
MyApplication.addOrderView(object : MyApplication.OrderStatueView {
|
override fun orderInfo(data: OrderSimpleData?) {
|
data?.let {
|
if (it.status == 10 || it.status == 11|| it.status == 12) {
|
MyApplication.currentOrderType = ""
|
MyApplication.currentOrderId = ""
|
Handler(Looper.getMainLooper()).post {
|
finish()
|
}
|
}
|
if ((it.orderType == 4 || it.orderType == 5) && it.orderId.toString() == orderId && (it.status != 10 && it.status != 11&& it.status != 12)) {
|
Handler(Looper.getMainLooper()).post {
|
callOrder() {}
|
}
|
}
|
}
|
}
|
})
|
}
|
|
var handler: Handler? = null
|
fun checkOrderStatue() {
|
var map = getMapByAny()
|
map["orderId"] = orderId
|
map["orderType"] = orderType
|
callNet(false, Api.orderStateSocket, map) {
|
val orderSimpleData =
|
Gson().fromJson(
|
it,
|
OrderSimpleData::class.java
|
)
|
orderSimpleData?.let {
|
if (it.status == 10||it.status == 12) {
|
MyApplication.currentOrderType = ""
|
MyApplication.currentOrderId = ""
|
Handler(Looper.getMainLooper()).post {
|
// MyApplication.getTTsManager().setVideoText(it.audioUrl)
|
finish()
|
}
|
}
|
}
|
|
}
|
handler?.postDelayed({ checkOrderStatue() }, 3000)
|
}
|
|
|
override fun onBackPressed() {
|
EventBus.getDefault().post(BaseEvent(BaseEvent.UPDATA_MAIN_CAR))
|
super.onBackPressed()
|
}
|
|
override fun finish() {
|
EventBus.getDefault().post(BaseEvent(BaseEvent.UPDATA_MAIN_CAR))
|
super.finish()
|
}
|
|
private fun onclick() {
|
tv_Right.clickDelay {
|
var map = getMapByAny()
|
map["orderId"] = orderId
|
map["orderType"] = orderType
|
callNet(Api.queryReassignMoney, map) {
|
val data = gson.fromJson<RessignBean>(it, RessignBean::class.java)
|
startActivity<ReassignActivity>(
|
"orderId" to orderId,
|
"orderType" to orderType
|
)
|
// if (data.data.amount.isNullOrEmpty()) {
|
//
|
// } else {
|
// DialogUtil.getDelAndSureDialog(
|
// this,
|
// getString(R.string.change_order_hint,data.data.amount!!),
|
// {},
|
// {
|
// //跳转改派页面
|
// startActivity<ReassignActivity>(
|
// "orderId" to orderId,
|
// "orderType" to orderType,
|
// "money" to data.data.amount.toString()
|
// )
|
// })
|
// }
|
|
|
}
|
}
|
|
btn_gap_money.clickDelay {
|
orderBean?.let { orderBean ->
|
if (orderBean.data.orderState == 13) {
|
toast(getString(R.string.用户已支付差价))
|
return@clickDelay
|
}
|
var dialog = DialogUtil.getDialog(this, R.layout.dialog_show_cha_money)
|
var viewContent = DialogUtil.getView(dialog)
|
val view_hint_close_car_cha = viewContent.find<View>(R.id.view_hint_close_car_cha)
|
val tv_car_num_close_cha = viewContent.find<View>(R.id.tv_car_num_close_cha)
|
val tv_sure_car_num_cha = viewContent.find<View>(R.id.tv_sure_car_num_cha)
|
val et_num_zg_cha = viewContent.find<EditText>(R.id.et_num_zg_cha)
|
view_hint_close_car_cha.setOnClickListener {
|
dialog.dismiss()
|
}
|
tv_car_num_close_cha.setOnClickListener {
|
dialog.dismiss()
|
}
|
tv_sure_car_num_cha.setOnClickListener {
|
var num = et_num_zg_cha.getContent()
|
if (num.isEmpty()) {
|
toast(getString(R.string.请输入金额))
|
return@setOnClickListener
|
}
|
if (num.toDouble() > 9999) {
|
toast(getString(R.string.金额不能大于9999元))
|
return@setOnClickListener
|
}
|
if (num.toDouble() <= 0) {
|
toast(getString(R.string.金额不能小于0元))
|
return@setOnClickListener
|
}
|
callseatmoney(num) {
|
dialog.dismiss()
|
btn_gap_money.text = getString(R.string.差价待确认).format(num.toDouble())
|
btn_gap_money.setCompoundDrawablesRelativeWithIntrinsicBounds(0,0,0,0)
|
// toast(getString(R.string.set_success))
|
}
|
}
|
}
|
}
|
|
tv_gap_money.clickDelay {
|
// btn_gap_money.callOnClick()
|
}
|
|
iv_move.setOnClickListener {
|
orderBean?.let {
|
when (it.data.orderState) {
|
2, 3 -> {
|
moveCamera(aMap, makeMarker!!.position, carMarker!!.position)
|
}
|
|
4 -> {
|
moveCamera(aMap, carMarker!!.position)
|
}
|
|
5, 6 -> {
|
moveCamera(aMap, carMarker!!.position, endMarker!!.position)
|
}
|
}
|
}
|
}
|
|
iv_police.clickDelay {
|
orderBean?.let {
|
MyUtils.getInstans().CallPhone(this, it.data.emergencyCall)
|
}
|
}
|
|
|
iv_to_gd.clickDelay {
|
orderBean?.let {
|
when (it.data.orderState) {
|
2, 3 -> {
|
startNavi(
|
carMarker!!.position.latitude,
|
carMarker!!.position.longitude,
|
makeMarker!!.position.latitude,
|
makeMarker!!.position.longitude
|
)
|
}
|
|
4 -> {
|
showToast(getString(R.string.没有终点无法导航))
|
}
|
|
5, 6 -> {
|
startNavi(
|
carMarker!!.position.latitude,
|
carMarker!!.position.longitude,
|
endMarker!!.position.latitude,
|
endMarker!!.position.longitude
|
)
|
}
|
}
|
}
|
}
|
|
// old 1=待接单,2=待出发,3=待到达预约地点,4=待取货,5=送货中,6=已送达,7=待支付,8=需补差价,9=已取货,10=已取消,11=改派中,12=已支付差价
|
// new 1=待接单,2=待出发,3=待到达预约地点,4=待乘客上车,5=服务中,6=完成服务,7=待支付,8=待评价,9=已完成,10=已取消,11=改派中,12=取消待支付,13=补差价
|
slide_btn.onSwipeListener = {
|
orderBean?.let {
|
when (it.data.orderState) {
|
2, 3, 4 -> {
|
if (it.data.orderState == 4) {
|
// showNumDialog { num ->
|
it.data.orderState++
|
callStatue("1", it.data.orderState) {
|
iv_to_gd.callOnClick()
|
}
|
showStatueMapUI(it)
|
// }
|
} else {
|
it.data.orderState++
|
callStatue(it.data.orderState, "") {
|
if (it.data.orderState == 3)
|
iv_to_gd.callOnClick()
|
}
|
showStatueMapUI(it)
|
}
|
}
|
|
5, 6 -> {
|
sendCode() {
|
it.data.orderState = 6
|
var dialog =
|
DialogUtil.getDialog(this, R.layout.dialog_show_cargo_money)
|
var viewContent = DialogUtil.getView(dialog)
|
val view_hint_close_car =
|
viewContent.find<View>(R.id.view_hint_close_car)
|
val tv_car_num_close = viewContent.find<View>(R.id.tv_car_num_close)
|
val tv_money = viewContent.find<TextView>(R.id.tv_money)
|
val tv_sure_car_num = viewContent.find<TextView>(R.id.tv_sure_car_num)
|
val et_num_zg = viewContent.find<EditText>(R.id.et_num_zg)
|
view_hint_close_car.setOnClickListener {
|
dialog.dismiss()
|
}
|
tv_car_num_close.setOnClickListener {
|
dialog.dismiss()
|
}
|
if (it.data.driverPay == "1") {
|
tv_money.visible()
|
tv_money.text =
|
getString(R.string.确认现金金额).format(if (it.data.payMoney == 0.0) it.data.orderMoney else it.data.payMoney)
|
.replace(",", ".")
|
}
|
tv_sure_car_num.setOnClickListener {
|
var num = et_num_zg.getContent()
|
if (num.isEmpty()) {
|
toast(getString(R.string.请输入验证码))
|
return@setOnClickListener
|
}
|
callStatue(orderBean!!.data.orderState, num) {
|
dialog.dismiss()
|
// startActivity<SmallOverActivity>(
|
// "orderId" to orderId,
|
// "orderType" to orderType
|
// )
|
/* startActivity<MajorSureMoneyActivity>(
|
"orderId" to orderId,
|
"orderType" to orderType
|
)*/
|
finish()
|
}
|
}
|
}
|
}
|
|
12 -> {
|
it.data.orderState = 5
|
callStatue(it.data.orderState, "") {}
|
showStatueMapUI(it)
|
}
|
|
8 -> {
|
// toast(getString(R.string.等待用户支付差价))
|
}
|
|
else -> {
|
|
}
|
}
|
}
|
}
|
|
iv_phone.clickDelay {
|
orderBean?.let {
|
MyUtils.getInstans().CallPhone(this, it.data.userPhone)
|
}
|
}
|
}
|
|
fun startNavi(startLat: Double, startLon: Double, endLat: Double, endLon: Double) {
|
AMapKit.startNavi(this, startLat, startLon, endLat, endLon)
|
}
|
|
private fun sendCode(function: () -> Unit) {
|
var map = getMapByAny()
|
map["orderId"] = orderId
|
callNet(Api.sendVerificationCode, map) {
|
function()
|
}
|
}
|
|
private fun callNumberCargo(num: String, click: () -> Unit) {
|
var map = getMapByAny()
|
map["orderId"] = orderId
|
map["pickUpCode"] = num
|
callNet(Api.fillInPickUpCode, map) {
|
click()
|
}
|
}
|
|
|
private fun callseatmoney(num: String, click: () -> Unit) {
|
var map = getMapByAny()
|
map["orderId"] = orderId
|
map["difference"] = doubleTwo(num.toDouble())
|
callNet(Api.makeUpTheDifference, map) {
|
click()
|
}
|
}
|
|
private fun callStatue(i: Int, num: String, click: () -> Unit) {
|
var map = getMapByAny()
|
map["orderId"] = orderId
|
map["orderType"] = orderType
|
map["state"] = i
|
if (!num.isNullOrEmpty())
|
map["pickUpCode"] = num
|
Log.e("定位==============》", "${MyApplication.getLocation()?.latitude},${MyApplication.getLocation()?.longitude}")
|
map["lat"] = MyApplication.getLocation()?.latitude ?: 0.0
|
map["lon"] = MyApplication.getLocation()?.longitude ?: 0.0
|
callNet(Api.process, map) {
|
OrderTimeOutManager.instance.checkOrderManager(orderId, orderType, i)
|
click()
|
}
|
}
|
|
private fun callStatue(phone: String, i: Int, click: () -> Unit) {
|
var map = getMapByAny()
|
map["orderId"] = orderId
|
map["orderType"] = orderType
|
map["state"] = i
|
// map["phone"] = phone
|
map["lat"] = MyApplication.getLocation()?.latitude ?: 0.0
|
map["lon"] = MyApplication.getLocation()?.longitude ?: 0.0
|
callNet(Api.process, map) {
|
OrderTimeOutManager.instance.checkOrderManager(orderId, orderType, i)
|
click()
|
}
|
}
|
|
private var movedByFinger = false
|
|
/***
|
* 定位时司机与线路的改变
|
*/
|
var lastMoveByGesture = 0L //上次手势操作的时间
|
private fun initMineLocation() {
|
aMap.setOnMyLocationChangeListener {
|
it.let { latlon ->
|
MyApplication.aMapLocation = LatLng(it.latitude,it.longitude)
|
}
|
orderBean?.let {
|
when (it.data.orderState) {
|
2, 3 -> {
|
changeCarThree(false)
|
}
|
4->{
|
//getTripInfo(4,false)
|
changeCarThree(false)
|
}
|
5, 6 -> {
|
changeCarFive(false)
|
}
|
}
|
}
|
|
// it.let { latlon ->
|
// carMarker?.position = LatLng(latlon.latitude, latlon.longitude)
|
// graylist.add(LatLng(latlon.latitude, latlon.longitude))
|
// grayline?.remove()
|
// grayline = AMapKit.drawLine(this, aMap, graylist, R.color.gray)
|
// MyApplication.aMapLocation = LatLng(it.latitude, it.longitude)
|
// orderBean?.let {
|
// when (it.data.orderState) {
|
// 2, 3 -> {
|
// changeCarThree(false)
|
// }
|
//
|
// 5, 6 -> {
|
// changeCarFive(false)
|
// }
|
// }
|
// }
|
// }
|
}
|
}
|
|
private fun changeCarThree(isMove: Boolean) {
|
if (makeMarker != null && carMarker != null) {
|
//getTripInfo(3,isMove)
|
AMapKit.initRouteLine(
|
this,
|
makeMarker!!.position,
|
carMarker!!.position,
|
object : (MutableList<LatLng>, Float, Long) -> Unit {
|
override fun invoke(p1: MutableList<LatLng>, p2: Float, p3: Long) {
|
|
val tance = AMapKit.getTance(this@SmallCargoActivity, p2)
|
val content = getString(R.string.距取货点, tance)
|
val sp = SpanBuilder.content(content)
|
.colorSpan(
|
this@SmallCargoActivity,
|
content.indexOf(tance),
|
content.indexOf(tance) + tance.length,
|
R.color.color_5DB03D
|
).build()
|
var view = creatCarView(sp)
|
carMarker!!.setIcon(getIcon(view))
|
addline(p1)
|
if (isMove)
|
moveCamera(aMap, makeMarker!!.position, carMarker!!.position)
|
}
|
})
|
}
|
}
|
|
private fun changeCarFive(isMove: Boolean) {
|
if (carMarker != null && endMarker != null) {
|
//getTripInfo(5,isMove)
|
AMapKit.initRouteLine(
|
this,
|
carMarker!!.position,
|
endMarker!!.position,
|
object : (MutableList<LatLng>, Float, Long) -> Unit {
|
override fun invoke(p1: MutableList<LatLng>, p2: Float, p3: Long) {
|
addline(p1)
|
|
val tance = AMapKit.getTance(this@SmallCargoActivity, p2)
|
val time = p3.toString()
|
val content = getString(R.string.预计还需, tance, time)
|
val sp = SpanBuilder.content(content).colorSpan(
|
this@SmallCargoActivity,
|
content.indexOf(tance),
|
content.indexOf(tance) + tance.length,
|
R.color.color_5DB03D
|
)
|
.colorSpan(
|
this@SmallCargoActivity,
|
content.indexOf(time),
|
content.indexOf(time) + time.length,
|
R.color.color_5DB03D
|
).build()
|
var view =
|
creatCarView(sp)
|
carMarker!!.setIcon(getIcon(view))
|
if (isMove) {
|
moveCamera(aMap, carMarker!!.position, endMarker!!.position)
|
}
|
}
|
})
|
}
|
}
|
|
private fun callOrder(reNavi:Boolean = false,function: () -> Unit) {
|
MyApplication.currentOrderId = orderId
|
MyApplication.currentOrderType = orderType
|
var map = getMapByAny()
|
map["orderId"] = orderId
|
map["orderType"] = orderType
|
callNet(Api.queryOrderInfo, map) {
|
orderBean = gson.fromJson(it, OrderBean::class.java)
|
showUi(orderBean)
|
function()
|
if (reNavi){
|
EventBus.getDefault().post(BaseEvent(BaseEvent.RELOAD_NAVI,orderBean!!.data.endLat.toString(),orderBean!!.data.endLon.toString()))
|
}
|
}
|
}
|
|
private fun showUi(orderBean: OrderBean?) {
|
orderBean?.let {
|
if (it.data.isFrozen == 2){
|
toast(getString(R.string.已冻结))
|
finish()
|
}
|
tv_name.text = orderBean.data.userName
|
// tv_name.text = orderBean.data.nickName
|
tv_car_num.text = getString(R.string.次寄物, it.data.historyNum.toString())
|
tv_time.text = it.data.travelTime_
|
tv_start_address.text = it.data.startAddress
|
tv_end_address.text = it.data.endAddress
|
showStatueMapUI(it)
|
// var cargoStrType = if (orderBean.data.cargoType == "1") "普通小件X" else "贵重物品X"
|
// tv_tv_num_cargo.text = cargoStrType + orderBean.data.peopleNumber
|
tv_people_cargo.text = orderBean.data.nickName + "-" + orderBean.data.phone
|
tv_remark.text = orderBean.data.remark
|
tv_money_cargo.gone()
|
// if (orderBean.data.tipMoney != null && orderBean.data.tipMoney > 0.0) {
|
// tv_money_cargo.text = doubleTwo(orderBean.data.tipMoney) + "元加急费"
|
// } else {
|
// tv_money_cargo.gone()
|
// }
|
if (!it.data.differenceMoney.isNullOrEmpty() && it.data.differenceMoney.toDouble() > 0) {
|
btn_gap_money.text = getString(R.string.差价点击修改).format(it.data.differenceMoney.toDouble())
|
btn_gap_money.setCompoundDrawablesRelativeWithIntrinsicBounds(0,0,0,0)
|
}
|
var latLngList = mutableListOf<LatLng>()
|
for (item in orderBean.data.orderPositionList) {
|
latLngList.add(LatLng(item.lat, item.lon))
|
}
|
graylist.clear()
|
graylist.addAll(latLngList)
|
grayline = AMapKit.drawLine(this, aMap, graylist, R.color.gray)
|
}
|
}
|
|
private fun getAllMark(it: OrderBean) {
|
if (makeMarker == null) {
|
val view = createView(R.layout.item_map_market_make, this)
|
view.find<ImageView>(R.id.iv_img).setImageResource(UiUtil.getLangResereveBitmap())
|
makeMarker = addMarker(aMap, it.data.startLat, it.data.startLon, view, "")
|
}
|
makeMarker!!.isVisible = false
|
if (startMarker == null) {
|
val view = createView(R.layout.item_map_market, this)
|
view.find<ImageView>(R.id.iv_img).setImageResource(UiUtil.getLangStartBitmap())
|
startMarker = addMarker(aMap, it.data.startLat, it.data.startLon, view, "")
|
}
|
startMarker!!.isVisible = false
|
if (endMarker == null) {
|
val view = createView(R.layout.item_map_market, this)
|
view.find<ImageView>(R.id.iv_img).setImageResource(UiUtil.getLangEndBitmap())
|
endMarker = addMarker(aMap, it.data.endLat, it.data.endLon, view, "")
|
}else{ //可能修改终点
|
endMarker?.position = LatLng(it.data.endLat, it.data.endLon)
|
}
|
endMarker!!.isVisible = false
|
if (carMarker == null) {
|
val carView = creatCarView("")
|
carMarker = addMarker(
|
aMap,
|
MyApplication.getLocation()?.latitude ?: 0.0,
|
MyApplication.getLocation()?.longitude ?: 0.0,
|
carView,
|
""
|
)
|
}
|
carMarker!!.isVisible = false
|
if (markerLine != null) {
|
markerLine!!.isVisible = false
|
}
|
}
|
|
fun creatCarView(content: CharSequence): View {
|
val carView = createView(R.layout.item_map_market, this)
|
carView.find<ImageView>(R.id.iv_img).setImageResource(R.mipmap.car_trip)
|
val tv_hint = carView.find<TextView>(R.id.tv_hint)
|
tv_hint.visible()
|
tv_hint.text = content
|
return carView
|
}
|
|
fun creatCarViewHint(content: CharSequence): View {
|
val carView = createView(R.layout.item_map_market, this)
|
carView.find<ImageView>(R.id.iv_img).setImageResource(R.mipmap.car_trip)
|
val tv_hint = carView.find<TextView>(R.id.tv_hint)
|
tv_hint.visible()
|
tv_hint.text = content
|
return carView
|
}
|
|
// 流程操作状态(3=开始出发预约点,4=到达预约点,5=开始服务,6=服务结束)
|
private fun showStatueMapUI(it: OrderBean) {
|
getAllMark(it)
|
tv_gap_money.gone()
|
btn_gap_money.gone()
|
if (it.data.orderState == 4 || it.data.orderState == 8 || it.data.orderState == 13) {
|
tv_gap_money.visible()
|
btn_gap_money.visible()
|
}
|
tv_Right.visible()
|
when (it.data.orderState) {
|
2, 3 -> {
|
if (it.data.reassign == 1) {
|
tv_Right.gone()
|
}
|
iv_to_gd.visible()
|
makeMarker?.isVisible = true
|
carMarker?.isVisible = true
|
changeCarThree(true)
|
closeTimeStart()
|
if (it.data.orderState == 2) {
|
slide_btn.changeButtonText(getString(R.string.出发前往取货地点))
|
setTitleText(getString(R.string.去领取货物))
|
} else {
|
slide_btn.changeButtonText(getString(R.string.到达取件地点))
|
setTitleText(getString(R.string.去领取货物))
|
}
|
}
|
// 4, 8, 12 -> {
|
4, 12 -> {
|
iv_to_gd.gone()
|
if (it.data.reassign == 1) {
|
tv_Right.gone()
|
}
|
closeLine()
|
carMarker?.isVisible = true
|
startTimeStart(
|
((System.currentTimeMillis() - DateUtil.dateToStamp(
|
DateUtil.TYPE0,
|
it.data.waitTime
|
)) / 1000).toInt()
|
)
|
moveCamera(aMap, carMarker!!.position)
|
setTitleText(getString(R.string.等待取货))
|
slide_btn.changeButtonText(getString(R.string.确认收货))
|
}
|
|
5, 6 -> {
|
closeTimeStart()
|
iv_to_gd.visible()
|
tv_Right.gone()
|
startMarker?.isVisible = true
|
endMarker?.isVisible = true
|
carMarker?.isVisible = true
|
changeCarFive(true)
|
setTitleText(getString(R.string.送货中))
|
slide_btn.changeButtonText(getString(R.string.确认送达))
|
}
|
}
|
}
|
|
private fun getTripInfo(state:Int,isMove: Boolean){
|
/* var map = getMapByAny()
|
map["orderId"] = orderId
|
map["orderType"] = orderType
|
Log.e("QXS=mmp","getTripInfo:state=${state},orderId=${orderId},orderType=${orderType}")
|
callNet(false,Api.getTripInfo, map) {
|
val bean = Gson().fromJson(it, StringBean::class.java)
|
if (bean.code == 200&&!bean.data.isNullOrEmpty()){
|
val trip = Gson().fromJson(bean.data, GoogleTripInfo::class.java)
|
val latlon = if (trip?.lastLocation == null) LocationX(MyApplication.aMapLocation!!.latitude,MyApplication.aMapLocation!!.longitude) else trip.lastLocation.location //车辆位置
|
carMarker?.position = LatLng(latlon.latitude, latlon.longitude)
|
if (state != 4){
|
graylist.add(LatLng(latlon.latitude, latlon.longitude))
|
grayline?.remove()
|
grayline = AMapKit.drawLine(this, aMap, graylist, R.color.gray)
|
val routs = arrayListOf<LatLng>()
|
if (!trip.route.isNullOrEmpty())
|
routs.addAll(trip.route.map { LatLng(it.latitude,it.longitude) })
|
addline(routs)
|
}else{
|
closeLine()
|
graylist.clear()
|
grayline?.remove()
|
}
|
if (state == 3){
|
val tance = AMapKit.getTance(this@SmallCargoActivity, trip.remainingDistanceMeters.toFloat())
|
val content = getString(R.string.距取货点, tance)
|
val sp = SpanBuilder.content(content)
|
.colorSpan(
|
this@SmallCargoActivity,
|
content.indexOf(tance),
|
content.indexOf(tance) + tance.length,
|
R.color.color_5DB03D
|
).build()
|
var view = creatCarView(sp)
|
carMarker!!.setIcon(getIcon(view))
|
}
|
if (state == 5){
|
val tance = AMapKit.getTance(this, trip.remainingDistanceMeters.toFloat())
|
val seconds = trip.remainingWaypoints?.firstOrNull()?.duration ?:"0s"
|
val time = (seconds.substring(0,seconds.length-1).toDouble()/60).toInt().toString()
|
val content = getString(R.string.预计还需, tance, time)
|
val sb = SpanBuilder.content(content).colorSpan(this,content.indexOf(tance),content.indexOf(tance)+tance.length,R.color.color_5DB03D)
|
.colorSpan(this,content.indexOf(time),content.indexOf(time)+time.length,R.color.color_5DB03D).build()
|
var view = creatCarView(sb)
|
carMarker!!.setIcon(getIcon(view))
|
}
|
if (isMove) {
|
iv_move.callOnClick()
|
}
|
}
|
}*/
|
}
|
|
|
private fun startTimeStart(waitTime: Int) {
|
if (!isTimeStart) {
|
isTimeStart = true
|
refreshTime(waitTime) {
|
val timeType = getTimeType(it)
|
val content = getString(R.string.您已等待, timeType)
|
val build = SpanBuilder.content(content).colorSpan(
|
this,
|
content.indexOf(timeType),
|
content.indexOf(timeType) + timeType.length,
|
R.color.main_login_orange
|
).build()
|
var view = creatCarViewHint(build)
|
carMarker!!.setIcon(getIcon(view))
|
}
|
}
|
}
|
|
private var timeDisposable: Disposable? = null
|
|
private fun refreshTime(waitTime: Int, click: (num: Int) -> Unit) {
|
if (null != timeDisposable && !timeDisposable!!.isDisposed) {
|
timeDisposable!!.dispose()
|
}
|
timeDisposable = Observable
|
.interval(1, TimeUnit.SECONDS)
|
.take(100000000)
|
.subscribeOn(Schedulers.computation())
|
.observeOn(AndroidSchedulers.mainThread())
|
.compose(bindUntilEvent(ActivityEvent.DESTROY))
|
.subscribe { aLong ->
|
var num = waitTime + aLong
|
click(num.toInt())
|
}
|
}
|
|
private fun closeTimeStart() {
|
if (timeDisposable != null) {
|
timeDisposable!!.dispose()
|
}
|
}
|
|
override fun onDestroy() {
|
super.onDestroy()
|
if (handler != null) {
|
handler?.removeCallbacksAndMessages(null)
|
}
|
closeTimeStart()
|
}
|
|
|
private fun addline(allLine: MutableList<LatLng>) {
|
closeLine()
|
markerLine = AMapKit.drawLine(this, aMap, allLine)
|
}
|
|
fun closeLine() {
|
if (markerLine != null) {
|
markerLine!!.remove()
|
}
|
}
|
|
fun getTance(startLatLng: LatLng, endLatLng: LatLng, onclick: (tance: Float) -> Unit) {
|
AMapKit.initRouteLine(
|
this,
|
startLatLng,
|
endLatLng,
|
object : (MutableList<LatLng>, Float, Long) -> Unit {
|
override fun invoke(p1: MutableList<LatLng>, p2: Float, p3: Long) {
|
onclick(p2)
|
}
|
})
|
}
|
|
override fun setOnclick() {
|
|
}
|
|
|
@SuppressLint("MissingPermission")
|
override fun onCreate(savedInstanceState: Bundle?) {
|
super.onCreate(savedInstanceState)
|
var fragment = supportFragmentManager.findFragmentById(R.id.map_view) as SupportMapFragment
|
initMap(fragment) {
|
mapInitStatus = true
|
aMap = it
|
aMap.isMyLocationEnabled = true
|
initView2()
|
it.setOnCameraMoveStartedListener {
|
movedByFinger = it == GoogleMap.OnCameraMoveStartedListener.REASON_GESTURE
|
}
|
it.setOnCameraMoveListener {
|
if (movedByFinger)
|
lastMoveByGesture = System.currentTimeMillis()
|
}
|
it.setOnCameraIdleListener {
|
movedByFinger = false
|
}
|
}
|
}
|
|
override fun onEventMainThread(event: BaseEvent?) {
|
super.onEventMainThread(event)
|
when (event!!.code) {
|
BaseEvent.REAGASSIGN_SUCCESS -> {
|
MyApplication.currentOrderId = ""
|
MyApplication.currentOrderType = ""
|
finish()
|
}
|
BaseEvent.BACK_CAR_OVER -> {
|
finish()
|
}
|
BaseEvent.DIFF_PRICE_AGREE -> {
|
if (mapInitStatus) initView2()
|
}
|
BaseEvent.DIFF_PRICE_REFUSE -> {
|
btn_gap_money.text = getString(R.string.补差价)
|
btn_gap_money.setCompoundDrawablesRelativeWithIntrinsicBounds(R.mipmap.ic_add,0,0,0)
|
}
|
BaseEvent.MODIFY_ADDRESS_SUC -> {
|
callOrder(true){}
|
}
|
}
|
}
|
}
|