GamblingDog
2025-09-09 141376c835204f1f1c33ddfbd365a8162e022a9c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package com.xianning.driver.ui.to_city
 
import android.os.Bundle
import android.os.CountDownTimer
import android.view.View
import cn.sinata.xldutils.activitys.DialogActivity
import cn.sinata.xldutils.utils.*
import com.baidu.mapapi.map.BaiduMap
import com.baidu.mapapi.model.LatLng
import com.google.gson.Gson
import com.xianning.driver.R
import com.xianning.driver.base.MyApplication
import com.xianning.driver.base.gaode.AMapKit
import com.xianning.driver.base.gaode.BaiduUtils
import com.xianning.driver.bean.OrderBean
import com.xianning.driver.netUtls.*
import com.xianning.driver.ui.UiUtil
import com.xianning.driver.ui.main.TripActivity
import kotlinx.android.synthetic.main.item_get_order.*
import kotlinx.android.synthetic.main.item_map_market.view.*
import org.jetbrains.anko.startActivity
 
class GetCityFragment : DialogActivity() {
 
    val orderId by lazy {
        intent?.getStringExtra("orderId")
    }
    val orderType by lazy {
        intent?.getStringExtra("orderType")
    }
 
    val timeDown by lazy {
        intent?.getIntExtra("time", 30)?:30
    }
    val type by lazy {
        intent?.getIntExtra("type", -1)
    }
 
    lateinit var time: CountDownTimer
 
 
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        //实例化语音引擎
        aMap = AMapKit.initMap(savedInstanceState, map_view)
        var strBtn = "确定"
        if (type == 1){
            strBtn = "抢单"
            time = timeOver((timeDown.toLong() * 1000L)) {
                if (it == 0) {
                    finish()
                } else {
                    tv_sure.text = strBtn + it.toString() + "S"
                }
            }
        }
        tv_sure.text = strBtn
        tv_close.clickDelay {
            finish()
        }
        callOrderDetail()
        tv_sure.clickDelay {
            if (type == 1) {
                showGetOrder()
            } else{
                this.startActivity<TripCityActivity>("orderId" to orderId, "orderType" to orderType)
                finish()
            }
        }
    }
    fun showGetOrder() {
        var map = getMapByAny()
        map["orderId"] = orderId
        map["orderType"] = orderType
        callNet(this, Api.grabOrder, map) {
            Toast.create(this).show("抢单成功")
            onBackPressed()
            when (orderType) {
                "3" -> {
                    this.startActivity<TripCityActivity>("orderId" to orderId, "orderType" to orderType)
                }
            }
        }
    }
    override fun initView() {
 
    }
 
 
    override fun setContentLayout(): Int {
        return R.layout.item_get_order
    }
 
 
    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
            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_yellow_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!!) + "订单"
            if (orderType!! == "3"){
                tv_money.setDrawableLeft(R.mipmap.icon_people_gray)
            }
            tv_remark.visibility = if (data.remark.isNullOrEmpty()) View.GONE else View.VISIBLE
            if (!data.remark.isNullOrEmpty()) {
                tv_remark.text = data.remark
            }
            if (orderType == "1") {
                tv_money.gone()
            }
            tv_start.text = data.startAddress
            tv_end.text = data.endAddress
            tv_money.text = data.people.toString() + "人"
            tv_reassign.text = data.type
            AMapKit.drawLineAndMove(
                this,
                aMap,
                LatLng(data.startLat, data.startLon),
                LatLng(data.endLat, data.endLon), 100
            )
            BaiduUtils.initRouteLine(
                LatLng(data.startLat, data.startLon),
                LatLng(data.endLat, data.endLon),null,
                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
                            )
                        )
                    }
 
                })
            BaiduUtils.initRouteLine(
                LatLng(MyApplication.getLocation().latitude, MyApplication.getLocation().longitude),
                LatLng(data.startLat, data.startLon),null,
                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: BaiduMap
 
}