package com.driver.igotrip.ui.main.small_cargo
|
|
import android.annotation.SuppressLint
|
import android.content.Intent
|
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 androidx.activity.result.ActivityResultLauncher
|
import androidx.activity.result.contract.ActivityResultContracts
|
import cn.sinata.rxnetty.LogHelper
|
import cn.sinata.xldutils.utils.*
|
import com.driver.igotrip.R
|
import com.driver.igotrip.base.BaseEvent
|
import com.driver.igotrip.base.Const
|
import com.driver.igotrip.base.MyApplication
|
import com.driver.igotrip.base.MyBaseActivity
|
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.extension.extClearInvalidZero
|
import com.driver.igotrip.netUtls.*
|
import com.driver.igotrip.ui.DialogUtil
|
import com.driver.igotrip.ui.UiUtil
|
import com.driver.igotrip.ui.main.MediaOperationActivity
|
import com.driver.igotrip.ui.main.ReassignActivity
|
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.LatLng
|
import com.google.android.gms.maps.model.Marker
|
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
|
|
//业务多媒体类型
|
var businessMediaType: Int = 0
|
|
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_phone1 by lazy { find<View>(R.id.iv_phone1) }
|
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) }
|
|
//跳转另一个页面并接收返回结果启动器
|
private lateinit var launcherForResult: ActivityResultLauncher<Intent>
|
|
override fun setContentView() {
|
setContentView(R.layout.activity_trip_cargo)
|
}
|
|
fun initView2() {
|
setTitleText("")
|
tv_Right.text = getString(R.string.申请改派短)
|
callOrder() {
|
initMineLocation()
|
}
|
onclick()
|
addSockectCancel()
|
|
val language = SPUtils.getString(Const.language)
|
if (language == Const.Language.ENGLISH || language == Const.Language.FRENCH)
|
btn_gap_money.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12f)
|
else
|
btn_gap_money.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14f)
|
LogHelper.logRecord("处理快件订单orderId:${orderId} orderType:${orderType}")
|
}
|
|
override fun initView() {
|
launcherForResult =
|
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
when (businessMediaType) {
|
0 -> {
|
if (result.resultCode == RESULT_OK && result.data != null) {
|
val result = result.data!!.getStringArrayListExtra("result")
|
showConfirmPriceDialog(result!!.joinToString(separator = ","))
|
} else {
|
|
}
|
}
|
|
1 -> {
|
if (result.resultCode == RESULT_OK && result.data != null) {
|
val result = result.data!!.getStringArrayListExtra("result")
|
showConfirmDeliveryDialog(result!!.joinToString(separator = ","))
|
} else {
|
|
}
|
}
|
}
|
}
|
}
|
|
private fun addSockectCancel() {
|
checkOrderStatue()
|
MyApplication.addOrderView(listener)
|
}
|
|
private val listener = 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() {
|
val map = getMapByAny()
|
map["orderId"] = orderId
|
map["orderType"] = orderType
|
callNet(false, Api.orderStateSocket, map) { it ->
|
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 {
|
val map = getMapByAny()
|
map["orderId"] = orderId
|
map["orderType"] = orderType
|
callNet(Api.queryReassignMoney, map, {
|
val data = gson.fromJson<RessignBean>(it, RessignBean::class.java)
|
LogHelper.logRecord("查询订单改派金额成功orderId:${orderId} orderType:${orderType} data:${Gson().toJson(data)}")
|
startActivity<ReassignActivity>(
|
"orderId" to orderId,
|
"orderType" to orderType
|
)
|
}) { code, msg ->
|
LogHelper.logRecord("查询订单改派金额失败orderId:${orderId} orderType:${orderType} code:${code} msg:${msg}")
|
}
|
}
|
|
btn_gap_money.clickDelay {
|
orderBean?.let { orderBean ->
|
if (orderBean.data.orderState == 13) {
|
toast(getString(R.string.用户已支付差价))
|
return@clickDelay
|
}
|
val dialog = DialogUtil.getDialog(this, R.layout.dialog_show_cha_money)
|
val 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 {
|
val 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, {
|
LogHelper.logRecord("补差价操作成功orderId:${orderId} orderType:${orderType}")
|
dialog.dismiss()
|
btn_gap_money.text =
|
getString(R.string.差价待确认).format(num.extClearInvalidZero())
|
btn_gap_money.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, 0, 0)
|
// toast(getString(R.string.set_success))
|
}) { code, msg ->
|
LogHelper.logRecord("补差价操作失败orderId:${orderId} orderType:${orderType} code:${code} msg:${msg}")
|
}
|
}
|
}
|
}
|
|
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) {
|
if (orderType == "4") {
|
businessMediaType = 0
|
launcherForResult.launch(
|
MediaOperationActivity.getIntent(
|
this,
|
getString(R.string.请上传图片),
|
getString(R.string.确认取货), 3, 1
|
)
|
)
|
} else {
|
it.data.orderState++
|
callStatue("1", it.data.orderState, {
|
LogHelper.logRecord("更新订单状态为送件中成功orderId:${orderId} orderType:${orderType}")
|
iv_to_gd.callOnClick()
|
}) { code, msg ->
|
it.data.orderState--
|
LogHelper.logRecord("更新订单状态为送件中失败orderId:${orderId} orderType:${orderType} code:${code} msg:${msg}")
|
}
|
showStatueMapUI(it)
|
}
|
} else {
|
it.data.orderState++
|
callStatue(it.data.orderState, "", {
|
LogHelper.logRecord("更新订单状态成功orderId:${orderId} orderType:${orderType} state:${it.data.orderState}")
|
if (it.data.orderState == 3)
|
iv_to_gd.callOnClick()
|
}) { code, msg ->
|
it.data.orderState--
|
LogHelper.logRecord("更新订单状态失败orderId:${orderId} orderType:${orderType} code:${code} msg:${msg}")
|
}
|
showStatueMapUI(it)
|
}
|
}
|
|
5, 6 -> {
|
// sendCode() {
|
businessMediaType = 1
|
launcherForResult.launch(
|
MediaOperationActivity.getIntent(
|
this,
|
getString(R.string.请上传图片),
|
getString(R.string.确认送达), 3, 1
|
)
|
)
|
// }
|
}
|
|
12 -> {
|
it.data.orderState = 5
|
callStatue(it.data.orderState, "", {
|
LogHelper.logRecord("取消待支付订单更新状态为送件中成功orderId:${orderId} orderType:${orderType}")
|
}) { code, msg ->
|
LogHelper.logRecord("取消待支付订单更新状态为送件中失败orderId:${orderId} orderType:${orderType} code:${code} msg:${msg}")
|
}
|
showStatueMapUI(it)
|
}
|
|
8 -> {
|
// toast(getString(R.string.等待用户支付差价))
|
}
|
|
else -> {
|
|
}
|
}
|
}
|
}
|
|
iv_phone.clickDelay {
|
orderBean?.let {
|
MyUtils.getInstans().CallPhone(this, it.data.userPhone)
|
}
|
}
|
iv_phone1.clickDelay {
|
orderBean?.let {
|
MyUtils.getInstans().CallPhone(this, it.data.phone)
|
}
|
}
|
|
}
|
|
//显示确认送达弹窗
|
private fun showConfirmDeliveryDialog(url: String) {
|
orderBean?.let {
|
it.data.orderState = 6
|
val dialog = DialogUtil.getDialog(this, R.layout.dialog_show_cargo_money)
|
val 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 (orderType == "4") it.data.expressPayAllMoney else if (it.data.payMoney.isNullOrEmpty()) it.data.orderMoney else it.data.payMoney)
|
.replace(",", ".").extClearInvalidZero()
|
}
|
tv_sure_car_num.setOnClickListener {
|
val num = et_num_zg.getContent()
|
if (num.isEmpty()) {
|
toast(getString(R.string.请输入验证码))
|
return@setOnClickListener
|
}
|
confirmDelivery(6, num, url, {
|
LogHelper.logRecord("确认快件已送达成功orderId:${orderId} orderType:${orderType}")
|
dialog.dismiss()
|
finish()
|
}) { code, msg ->
|
LogHelper.logRecord("确认快件已送达失败orderId:${orderId} orderType:${orderType} code:${code} msg:${msg}")
|
}
|
}
|
}
|
}
|
|
//显示确认价格弹窗
|
private fun showConfirmPriceDialog(url: String) {
|
orderBean?.let {
|
DialogUtil.getDelAndSureDialog(
|
this,
|
getString(R.string.确认现金金额).format(it.data.expressPayAllMoney)
|
.replace(",", ".").extClearInvalidZero(),
|
{},
|
{
|
confirmPickUp(url, 5, {
|
LogHelper.logRecord("确认收到此订单费用成功orderId:${orderId} orderType:${orderType}")
|
it.data.orderState = 5
|
showStatueMapUI(it)
|
iv_to_gd.callOnClick()
|
}) { code, msg ->
|
LogHelper.logRecord("确认收到此订单费用失败orderId:${orderId} orderType:${orderType} code:${code} msg:${msg}")
|
}
|
})
|
}
|
}
|
|
fun startNavi(startLat: Double, startLon: Double, endLat: Double, endLon: Double) {
|
AMapKit.startNavi(this, startLat, startLon, endLat, endLon)
|
}
|
|
private fun callseatmoney(num: String, click: () -> Unit, error: (code: Int, msg: String?) -> Unit) {
|
val map = getMapByAny()
|
map["orderId"] = orderId
|
map["difference"] = doubleTwo(num.toDouble())
|
callNet(Api.makeUpTheDifference, map, {
|
click()
|
}, error)
|
}
|
|
private fun callStatue(i: Int, num: String, click: () -> Unit, error: (code: Int, msg: String?) -> Unit) {
|
val map = getMapByAny()
|
map["orderId"] = orderId
|
map["orderType"] = orderType
|
map["state"] = i
|
if (num.isNotEmpty())
|
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, {
|
click()
|
}, error)
|
}
|
|
//确认送达
|
private fun confirmDelivery(i: Int, num: String, imgTwo: String, click: () -> Unit, error: (code: Int, msg: String?) -> Unit) {
|
val map = getMapByAny()
|
map["orderId"] = orderId
|
map["orderType"] = orderType
|
map["state"] = i
|
if (num.isNotEmpty())
|
map["pickUpCode"] = num
|
Log.e(
|
"定位==============》",
|
"${MyApplication.getLocation()?.latitude},${MyApplication.getLocation()?.longitude}"
|
)
|
map["imgTwo"] = imgTwo
|
map["lat"] = MyApplication.getLocation()?.latitude ?: 0.0
|
map["lon"] = MyApplication.getLocation()?.longitude ?: 0.0
|
callNet(Api.process, map, {
|
click()
|
}, error)
|
}
|
|
private fun callStatue(phone: String, i: Int, click: () -> Unit, error: (code: Int, msg: String?) -> Unit) {
|
val 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, {
|
click()
|
}, error)
|
}
|
|
//确认收获
|
private fun confirmPickUp(imgOne: String, i: Int, click: () -> Unit, error: (code: Int, msg: String?) -> Unit) {
|
val map = getMapByAny()
|
map["orderId"] = orderId
|
map["orderType"] = orderType
|
map["imgOne"] = imgOne
|
map["state"] = i
|
map["lat"] = MyApplication.getLocation()?.latitude ?: 0.0
|
map["lon"] = MyApplication.getLocation()?.longitude ?: 0.0
|
callNet(Api.process, map, {
|
click()
|
}, error)
|
}
|
|
private var movedByFinger = false
|
|
/***
|
* 定位时司机与线路的改变
|
*/
|
var lastMoveByGesture = 0L //上次手势操作的时间
|
private fun initMineLocation() {
|
aMap.setOnMyLocationChangeListener { it ->
|
it?.let {
|
MyApplication.setLocation(it.latitude, it.longitude)
|
}
|
orderBean?.let {
|
when (it.data.orderState) {
|
2, 3 -> {
|
changeCarThree(false)
|
}
|
|
4 -> {
|
//getTripInfo(4,false)
|
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) {
|
if (isFinishing || isDestroyed) {
|
return
|
}
|
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()
|
val 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) {
|
if (isFinishing || isDestroyed) {
|
return
|
}
|
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()
|
val 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
|
val map = getMapByAny()
|
map["orderId"] = orderId
|
map["orderType"] = orderType
|
callNet(Api.queryOrderInfo, map) { it ->
|
gson.fromJson(it, OrderBean::class.java)?.also {
|
orderBean = it
|
showUi(it)
|
function()
|
if (reNavi) {
|
EventBus.getDefault().post(
|
BaseEvent(
|
BaseEvent.RELOAD_NAVI,
|
it.data?.endLat?.toString(),
|
it.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.extClearInvalidZero())
|
btn_gap_money.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, 0, 0)
|
}
|
val 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 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()
|
val 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 ->
|
val num = waitTime + aLong
|
click(num.toInt())
|
}
|
}
|
|
private fun closeTimeStart() {
|
if (timeDisposable != null) {
|
timeDisposable!!.dispose()
|
}
|
}
|
|
override fun onDestroy() {
|
super.onDestroy()
|
MyApplication.removeOrderView(listener)
|
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()
|
}
|
}
|
|
override fun setOnclick() {
|
|
}
|
|
@SuppressLint("MissingPermission")
|
override fun onCreate(savedInstanceState: Bundle?) {
|
super.onCreate(savedInstanceState)
|
val 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) {}
|
}
|
}
|
}
|
}
|