liugl
2021-01-28 4873e23bebf15d2093ee99012d92794faeac474c
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
package com.okgoincar.slab
 
import android.annotation.SuppressLint
import android.content.pm.ActivityInfo
import android.os.Bundle
import android.os.CountDownTimer
import cn.sinata.xldutils.activitys.DialogActivity
import cn.sinata.xldutils.utils.*
import com.amap.api.maps.model.LatLng
import com.okgoincar.netUtls.*
import com.okgoincar.slab.util.UiUtil
import com.google.gson.Gson
import com.okgoincar.R
import com.okgoincar.base.AMapKit
import com.okgoincar.base.MyApplication
import com.okgoincar.bean.OrderBean
import com.okgoincar.bean.ServerVoiceBean
import com.okgoincar.netUtls.Api
import kotlinx.android.synthetic.main.item_get_order.*
import kotlinx.android.synthetic.main.item_map_market.view.*
import org.jetbrains.anko.startActivity
import org.jetbrains.anko.toast
 
class SlabGetOrderFragment : DialogActivity() {
 
    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)
    }
 
    lateinit var time: CountDownTimer
 
 
    @SuppressLint("SourceLockedOrientationActivity", "SetTextI18n")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        //设置竖屏显示
        requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
        callOrderDetail()
        callVideo()
        var strBtn = "抢单"
        if (type == 2){
            strBtn = "确定"
        }
        time = timeOver ((timeDown!!.toLong() * 1000L)){
            if (it == 0) {
                finish()
            } else {
                tv_sure.text = strBtn + it.toString() + "秒"
            }
        }
 
        tv_close.clickDelay {
            finish()
        }
 
        tv_sure.clickDelay {
            if (type == 1){
                showGetOrder()
            }else if (type == 2){
                onBackPressed()
                this.startActivity<SlabTripActivity>("orderId" to orderId, "orderType" to orderType)
            }
        }
        setblack(getNowTimeBlack())
    }
 
    private fun callVideo() {
        var map = getMapByAny()
        map["orderId"] = orderId
        map["orderType"] = orderType
        map["lat"] = MyApplication.getLocation().latitude
        map["lon"] = MyApplication.getLocation().longitude
        callNet(this,Api.queryVoiceBroadcast,map){
            var bean = Gson().fromJson<ServerVoiceBean>(it,ServerVoiceBean::class.java)
            if (!bean.data.isNullOrEmpty()){
                MyApplication.getTTsManager().setVideoText(bean.data)
                var str = bean.data
                str = str.substring(7,str.indexOf("公里"))
                tv_title.text = "距您约"+str+"公里"
            }
        }
    }
 
    override fun initView() {
 
    }
 
    override fun onDestroy() {
        super.onDestroy()
        time.cancel()
    }
 
    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
            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)
            tv_time.text = data.travelTime
            tv_car_type.text = UiUtil.getNameByType(orderType!!)
            tv_start.text = data.startAddress
            if(data.endAddress.isNullOrEmpty()){
                tv_end.gone()
            }
            tv_end.text = data.endAddress
            tv_money.text = data.tipMoney.toString() + "元红包"
            tv_reassign.text = data.type
            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
                    ) {
//                        MyApplication.getTTsManager().setVideoText("收到新的"+
//                                UiUtil.getNameByType(orderType!!)+"订单,"+"从"+data.startAddress+"出发,距您约"+AMapKit.getTance(lineTance))
                    }
                })
        }
    }
 
    private fun setblack(nowTimeBlack: Boolean) {
        if (nowTimeBlack){
            rl_top_back.setBackgroundResource(R.color.black_mode_383838)
            ll_order_top.setBackgroundResource(R.color.black_mode_383838)
            tv_time.textColor(this,R.color.white)
            tv_start.textColor(this,R.color.white)
            tv_end.textColor(this,R.color.white)
            tv_money.textColor(this,R.color.white)
            tv_title.textColor(this,R.color.slab_yellow_zhong)
        }else{
            rl_top_back.setBackgroundResource(R.color.white)
            ll_order_top.setBackgroundResource(R.color.white)
            tv_time.textColor(this,R.color.black)
            tv_start.textColor(this,R.color.black)
            tv_end.textColor(this,R.color.black)
            tv_money.textColor(this,R.color.black)
            tv_title.textColor(this,R.color.yellow_ffa72d)
        }
    }
 
 
    fun showGetOrder() {
        var map = getMapByAny()
        map["orderId"] = orderId
        map["orderType"] = orderType
        showDialog()
        callNet(this, Api.grabOrder_, map, {
            dismissDialog()
            Toast.create(this).show("抢单成功")
            onBackPressed()
            this.startActivity<SlabTripActivity>("orderId" to orderId, "orderType" to orderType)
        },{
            toast(it!!)
            dismissDialog()
        })
    }
 
 
}