package com.kuanzhai.driver.ui.main
|
|
import android.Manifest
|
import android.os.Bundle
|
import android.os.CountDownTimer
|
import android.view.View
|
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.RecyclerView
|
import cn.sinata.xldutils.activitys.DialogActivity
|
import cn.sinata.xldutils.utils.*
|
import com.amap.api.maps.AMap
|
import com.amap.api.maps.model.LatLng
|
import com.kuanzhai.driver.R
|
import com.kuanzhai.driver.base.MyApplication
|
import com.kuanzhai.driver.base.gaode.AMapKit
|
import com.kuanzhai.driver.bean.OrderBean
|
import com.kuanzhai.driver.netUtls.*
|
import com.kuanzhai.driver.ui.UiUtil
|
import com.kuanzhai.driver.ui.adapter.SmallUserImgAdapter
|
import com.kuanzhai.driver.ui.main.small_cargo.SmallCargoActivity
|
import com.kuanzhai.driver.ui.to_city.TripCityActivity
|
import com.google.gson.Gson
|
import com.kuanzhai.driver.ui.DialogUtil
|
import com.kuanzhai.driver.ui.main.add_order.AddCityOrderActivity
|
import com.tbruyelle.rxpermissions2.RxPermissions
|
import kotlinx.android.synthetic.main.item_get_order.*
|
import kotlinx.android.synthetic.main.item_map_market.view.*
|
import org.jetbrains.anko.startActivity
|
|
class GetOrderFragment : DialogActivity() {
|
|
// 1.上班:您正在上班中 或者 xx出行,美好生活
|
// 2.下班:您已下班
|
// 3.收到订单:您收到新的【快车/出租车】【实时/预约】订单,距您xx公里,从xx出发,全程约xx公里
|
// 4.修改终点:请注意,乘客已修改终点
|
|
val orderId by lazy {
|
intent?.getStringExtra("orderId")
|
}
|
val orderType by lazy {
|
intent?.getStringExtra("orderType")
|
}
|
|
val timeDown by lazy {
|
intent?.getIntExtra("time", -1)
|
}
|
val type by lazy {
|
intent?.getIntExtra("type", -1)
|
}
|
|
val smallUserImgAdapter by lazy {
|
SmallUserImgAdapter()
|
}
|
|
lateinit var time: CountDownTimer
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
super.onCreate(savedInstanceState)
|
//实例化语音引擎
|
aMap = AMapKit.initMap(savedInstanceState, map_view)
|
callOrderDetail()
|
var strBtn = "抢单"
|
if (type == 2) {
|
strBtn = "确定"
|
}
|
time = timeOver((timeDown!!.toLong() * 1000L)) {
|
if (it == 0) {
|
finish()
|
} else {
|
tv_sure.text = strBtn + it.toString() + "S"
|
}
|
}
|
tv_close.clickDelay {
|
finish()
|
}
|
tv_sure.clickDelay {
|
RxPermissions(this).request(Manifest.permission.RECORD_AUDIO).subscribe {
|
if (it)
|
if (type == 1) {
|
showGetOrder()
|
} else if (type == 2) {
|
onBackPressed()
|
this.startActivity<TripActivity>("orderId" to orderId, "orderType" to orderType)
|
}
|
else{
|
DialogUtil.getOnlySureDialog(this,"抢单下单功能不可用"){}
|
}
|
}
|
}
|
}
|
|
override fun initView() {
|
|
}
|
|
override fun onPause() {
|
super.onPause()
|
|
}
|
|
override fun onDestroy() {
|
super.onDestroy()
|
time.cancel()
|
}
|
|
override fun setContentLayout(): Int {
|
return R.layout.item_get_order
|
}
|
|
|
var mainData:OrderBean.DataBean? = null
|
|
private fun callOrderDetail() {
|
|
var map = getMapByAny()
|
map["orderId"] = orderId
|
map["orderType"] = orderType
|
map["lat"] = MyApplication.getLocation().latitude
|
map["lon"] = MyApplication.getLocation().longitude
|
callNet(this, Api.queryPushOrder, map) {
|
val data = Gson().fromJson<OrderBean>(it, OrderBean::class.java).data
|
mainData = data
|
sysErr(data)
|
val startView = createView(R.layout.item_map_market, this)
|
val endView = createView(R.layout.item_map_market, this)
|
startView.iv_img.setImageResource(R.mipmap.starting_point)
|
endView.iv_img.setImageResource(R.mipmap.end_point)
|
AMapKit.addMarker(aMap, data.startLat, data.startLon, startView, "")
|
AMapKit.addMarker(aMap, data.endLat, data.endLon, endView, "")
|
tv_time.text = data.travelTime
|
tv_car_type.text = UiUtil.getNameByType(orderType!!) + "订单"
|
tv_remark.visibility = if (data.remark.isNullOrEmpty()) View.GONE else View.VISIBLE
|
tv_end.visibility = if (data.endAddress.isNullOrEmpty()) View.GONE else View.VISIBLE
|
tv_tance.visibility = if (data.endAddress.isNullOrEmpty()) View.GONE else View.VISIBLE
|
|
if (!data.remark.isNullOrEmpty()) {
|
tv_remark.text = data.remark
|
}
|
if (orderType == "1") {
|
tv_money.gone()
|
if (data.rideType == "3"){
|
tv_title_hint.text = "拼车"
|
tv_title_hint.visible()
|
tv_name.text = "乘坐人数共"+ data.peopleNumber+"人"
|
tv_name.visible()
|
}
|
}
|
if (orderType == "5" || orderType == "4") {
|
if (data.arriveTimeExpect.isNotEmpty()){
|
tv_expect_time.text = "要求送达时间:"+data.arriveTimeExpect
|
tv_expect_time.visible()
|
}
|
tv_money.gone()
|
tv_remark.gone()
|
tv_name.visible()
|
ll_cargo_num.visible()
|
tv_cargo_money.visible()
|
tv_name.text = data.nickName + "-" + data.phone
|
var cargoStrType = if (data.cargoType == "1") "普通小件X" else "贵重物品X"
|
tv_cargo_num.text = cargoStrType + data.peopleNumber
|
recycler_view_user_img.layoutManager = LinearLayoutManager(this, RecyclerView.HORIZONTAL,false)
|
recycler_view_user_img.adapter = smallUserImgAdapter
|
var list = data.userImg.split(",")
|
smallUserImgAdapter.data.addAll(list)
|
smallUserImgAdapter.notifyDataSetChanged()
|
if (data.tipMoney != null && data.tipMoney > 0.0) {
|
tv_cargo_money.text = doubleTwo(data.tipMoney) + "元加急费"
|
} else {
|
tv_cargo_money.gone()
|
}
|
}
|
tv_start.text = data.startAddress
|
tv_end.text = data.endAddress
|
tv_money.text = data.tipMoney.toString() + "元小费"
|
tv_reassign.text = data.type
|
|
if (data.endLat != null && data.endLon != null) {
|
AMapKit.drawLineAndMove(
|
this,
|
aMap,
|
LatLng(data.startLat, data.startLon),
|
LatLng(data.endLat, data.endLon), 100
|
)
|
AMapKit.initRouteLine(
|
this,
|
LatLng(data.startLat, data.startLon),
|
LatLng(data.endLat, data.endLon),
|
object : (MutableList<LatLng>, Float, Long) -> Unit {
|
override fun invoke(
|
latLngs: MutableList<LatLng>,
|
lineTance: Float,
|
lineTime: Long
|
) {
|
tv_tance.text = "全程约" + AMapKit.getTance(lineTance)
|
MyApplication.getTTsManager().setVideoText(
|
"收到新的" + UiUtil.getNameByType(orderType!!) + "订单," + "从" + data.startAddress + "出发,全程约" + AMapKit.getTance(
|
lineTance
|
)
|
)
|
}
|
|
})
|
}else{
|
AMapKit.moveCamera(aMap,LatLng(data.startLat, data.startLon))
|
MyApplication.getTTsManager().setVideoText(
|
"收到新的" + UiUtil.getNameByType(orderType!!) + "订单," + "从" + data.startAddress + "出发"
|
)
|
}
|
|
AMapKit.initRouteLine(
|
this,
|
LatLng(MyApplication.getLocation().latitude, MyApplication.getLocation().longitude),
|
LatLng(data.startLat, data.startLon),
|
object : (MutableList<LatLng>, Float, Long) -> Unit {
|
override fun invoke(
|
latLngs: MutableList<LatLng>,
|
lineTance: Float,
|
lineTime: Long
|
) {
|
tv_title.text = "距您约" + AMapKit.getTance(lineTance)
|
}
|
})
|
}
|
}
|
|
lateinit var aMap: AMap
|
|
fun showGetOrder() {
|
var map = getMapByAny()
|
map["orderId"] = orderId
|
map["orderType"] = orderType
|
callNet(this, Api.grabOrder, map) {
|
Toast.create(this).show("抢单成功")
|
onBackPressed()
|
when (orderType) {
|
"2","10" -> {
|
this.startActivity<TripActivity>("orderId" to orderId, "orderType" to orderType)
|
}
|
"1" -> {
|
mainData?.let {
|
if (it.rideType == "3"){
|
this.startActivity<TripPoolingActivity>("orderId" to orderId, "orderType" to orderType)
|
}else{
|
this.startActivity<TripActivity>("orderId" to orderId, "orderType" to orderType)
|
}
|
}
|
}
|
"3","8","9" -> {
|
this.startActivity<TripCityActivity>(
|
"orderId" to orderId,
|
"orderType" to orderType
|
)
|
}
|
"4", "5" -> {
|
this.startActivity<SmallCargoActivity>(
|
"orderId" to orderId,
|
"orderType" to orderType
|
)
|
}
|
}
|
}
|
}
|
}
|