fix
lmw
2023-03-14 128cbeac95dbc995fe1760bbd0f0a985fa5d23ba
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
package com.fuban.user.ui.trip
 
import android.app.Activity
import android.graphics.Color
import android.os.Bundle
import android.view.View
import android.widget.CheckBox
import androidx.core.os.bundleOf
import cn.sinata.xldutils.gone
import cn.sinata.xldutils.invisible
import cn.sinata.xldutils.utils.SPUtils
import cn.sinata.xldutils.utils.myToast
import cn.sinata.xldutils.utils.optDouble
import cn.sinata.xldutils.visible
import com.amap.api.maps.CameraUpdateFactory
import com.amap.api.maps.MapView
import com.amap.api.maps.model.*
import com.fuban.user.R
import com.fuban.user.network.Apis
import com.fuban.user.network.HttpManager
import com.fuban.user.network.entity.Order
import com.fuban.user.network.entity.Point
import com.fuban.user.network.request
import com.fuban.user.ui.TransparentStatusBarActivity
import com.fuban.user.dialog.ShareDialog
import com.fuban.user.dialog.TipDialog
import com.fuban.user.utils.Const
import com.share.utils.ShareUtils
import com.umeng.socialize.UMShareListener
import com.umeng.socialize.bean.SHARE_MEDIA
import kotlinx.android.synthetic.main.activity_map_order_detail.*
import org.jetbrains.anko.find
import org.jetbrains.anko.sdk27.coroutines.onClick
import org.jetbrains.anko.startActivity
 
class OrderDetailWithMapActivity :TransparentStatusBarActivity(),UMShareListener {
    override fun setContentView() = R.layout.activity_map_order_detail
 
    private val id by lazy {
        intent.getIntExtra("id",0)
    }
    private val type by lazy {
        intent.getIntExtra("type",0)
    }
    private var score = 0
    private var order: Order? = null
    private val points = arrayListOf<Point>()
 
    private val lowList = arrayListOf(
        "道路不熟", "服务态度恶劣", "车辆肮脏", "车内有异味", "车牌号不符",
        "司机吸烟", "打电话玩手机", "未坐好就开车", "未提醒系安全带", "未提醒开门注意", "过路口不减速", "索要好评"
    )
    private val highList = arrayListOf("车内整洁", "活地图认路准", "驾驶平稳", "态度好服务棒")
    private val checkList = arrayListOf<String>()
    private val mMapView by lazy {
        find<MapView>(R.id.mMapView)
    }
    private val aMap by lazy {
        mMapView.map
    }
 
    override fun initClick() {
        tv_money.onClick {
            startActivity<PriceDetailActivity>("order" to order)
        }
 
        rating.setOnRatingChangeListener {
            if (!rating.clickable)
                return@setOnRatingChangeListener
            tv_action.visible()
            if (it == 5f && score != 5) {
                inputLabel(true)
            }
            if (it != 5f && (score == 0 || score == 5)) {
                inputLabel(false)
            }
            score = it.toInt()
        }
 
        tv_action.setOnClickListener {
            HttpManager.orderEvaluate(id,score,type,checkList.joinToString (","){ it }).request(this){_,_->
                setResult(Activity.RESULT_OK)
                myToast("评价成功")
                tv_action.gone()
                tv_title.text = "评价详情"
                rating.isClickable = false
                getData()
                getRedMoney()
            }
        }
 
        tv_name.setOnClickListener {
            startActivity<DriverDetailActivity>("id" to order!!.driverId)
        }
    }
 
    override fun initView() {
        title = "订单详情"
//        titleBar.addRightButton("开发票",onClickListener = View.OnClickListener {
//
//        })
        getData()
        queryTrack()
        initMap()
    }
 
    private fun initMap() {
        aMap.uiSettings.isMyLocationButtonEnabled = false//设置默认定位按钮是否显示,非必需设置。
        aMap.uiSettings.setZoomInByScreenCenter(true)
        aMap.uiSettings.isZoomControlsEnabled = false
        aMap.uiSettings.isRotateGesturesEnabled = false
        aMap.uiSettings.isTiltGesturesEnabled = false
    }
 
    private fun getData(){
        HttpManager.queryOrderInfo(id,type).request(this){ _, data->
            order = data
            data?.run {
                tv_name.text = "$driverName $licensePlate"
                tv_car_info.text = "$brand·$carColor"
                tv_score.text = String.format("%.1f",score)
                if (payMoney == 0.0)
                    tv_money.invisible()
                else
                    tv_money.text = String.format("%.2f元",payMoney)
                if (startMarker == null)
                    setMarker(LatLng(startLat,startLon))
                if (endMarker == null)
                    setMarker(LatLng(endLat,endLon),false)
                val builder = LatLngBounds.builder()
                builder.include(LatLng(startLat,startLon)).include(
                    LatLng(endLat,endLon))
                aMap.moveCamera(CameraUpdateFactory.newLatLngBoundsRect(builder.build(), 100,100,200,1100))
                setStateUI()
                if (points.isNotEmpty()&&routeOverlay == null)
                    setRoute()
            }
        }
    }
 
    private fun setStateUI() {
        when(order?.state){
            8->{ //待评价
                tv_title.text = "匿名评价司机"
            }
            9->{ //已完成
                tv_title.text = "评价详情"
                rating.isClickable = false
                rating.setStar(order!!.orderScore.toFloat())
                fl_label.removeAllViews()
                val list = arrayListOf<String>()
                list.addAll(if (order!!.orderScore == 5) highList else lowList)
                val split = order!!.evaluate.split(",")
                list.forEach {
                    val view = layoutInflater.inflate(R.layout.item_score_label, null) as CheckBox
                    view.text = it
                    view.isEnabled = false
                    if (it in split)
                        view.isChecked = true
                    fl_label.addView(view)
                }
            }
        }
    }
 
    private fun queryTrack(){
        HttpManager.queryTrack(id,type).request(this){_,data->
            data?.let {
                points.addAll(it)
                if (order!=null){
                    setRoute()
                }
            }
        }
    }
 
    private fun inputLabel(isHigh: Boolean) {
        fl_label.removeAllViews()
        checkList.clear()
        val list = arrayListOf<String>()
        list.addAll(if (isHigh) highList else lowList)
        list.forEach {
            val view = layoutInflater.inflate(R.layout.item_score_label, null) as CheckBox
            view.text = it
            view.setOnCheckedChangeListener { _, isChecked ->
                if (isChecked)
                    checkList.add(view.text.toString())
                else
                    checkList.remove(view.text.toString())
            }
            fl_label.addView(view)
        }
    }
 
    private var routeOverlay: Polyline? = null
    private fun setRoute(){
        val polylineOptions = PolylineOptions()
        polylineOptions.color(Color.parseColor("#00C47A")).width(18f)
//        polylineOptions.add(LatLng(order!!.startLat,order!!.startLon))
        points.map { LatLng(it.lat,it.lon) }.forEach {
            polylineOptions.add(it)
        }
//        polylineOptions.add(LatLng(order!!.endLat,order!!.endLon))
        routeOverlay = aMap.addPolyline(polylineOptions)
    }
    private var startMarker: Marker? = null
    private var endMarker: Marker? = null
 
    /**
     * @param isStart true:起点标记 false:终点标记
     */
    private fun setMarker(latLon: LatLng, isStart:Boolean = true) {
        if (isStart){
            val icon = BitmapDescriptorFactory.fromResource(R.mipmap.starting_point)
            val options = MarkerOptions()
            options.position(latLon).icon(icon)
            startMarker = aMap.addMarker(options)
        }else{
            val options = MarkerOptions()
            options.position(latLon).icon(BitmapDescriptorFactory.fromResource(R.mipmap.end_point))
            endMarker = aMap.addMarker(options)
        }
    }
 
    /**
     * 评价成功以后需要查询是否可以获得分享红包
     */
    private fun getRedMoney(){
        HttpManager.queryRedMoney(id,type).request(this){_,data->
            data?.let {
                val money = it.optDouble("amount")
                if (money>0){
                    val tipDialog = TipDialog()
                    tipDialog.arguments = bundleOf("msg" to String.format("分享APP给好友可以获得%.2f元打车红包",money),
                        "ok" to "去分享","cancel" to "不分享")
                    tipDialog.setCallback(object :TipDialog.OnClickCallback{
                        override fun onOk() {
                            val shareDialog = ShareDialog()
                            shareDialog.setCallback(object :ShareDialog.Callback{
                                override fun onOk(way: Int) { //0:wx 1:qq 2:msg
                                    ShareUtils.share(this@OrderDetailWithMapActivity,if (way == 0) SHARE_MEDIA.WEIXIN else if (way == 1) SHARE_MEDIA.QQ else
                                        SHARE_MEDIA.MORE, Const.Share.NORMAL_CONTENT,Const.Share.TITLE,
                                        String.format(Apis.SHARE_URL, SPUtils.instance().getInt(Const.User.USER_ID)),this@OrderDetailWithMapActivity,"")
                                    shareDialog.dismiss()
                                    getRed(money)
                                }
                            })
                            shareDialog.show(supportFragmentManager,"share")
                        }
 
                        override fun onCancel() {}
                    })
                    tipDialog.show(supportFragmentManager,"red")
                }
            }
        }
    }
 
    /**
     * 分享后获得红包
     */
    private fun getRed(money:Double){
        HttpManager.shareRedEnvelope(id,type).request(this){_,_->
            val tipDialog = TipDialog()
            tipDialog.arguments = bundleOf("msg" to String.format("您收到一个%.2f元的打车红包,已经放入钱包,下次打车可抵扣金额",money),
                "ok" to "确定","isAlert" to true)
            tipDialog.show(supportFragmentManager,"red")
        }
    }
 
    override fun onResume() {
        super.onResume()
        mMapView.onResume()
    }
 
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mMapView.onCreate(savedInstanceState)
    }
 
    override fun onSaveInstanceState(outState: Bundle) {
        super.onSaveInstanceState(outState)
        mMapView.onSaveInstanceState(outState)
    }
 
    override fun onLowMemory() {
        super.onLowMemory()
        mMapView.onLowMemory()
    }
 
    override fun onPause() {
        super.onPause()
        mMapView.onPause()
    }
 
    override fun onDestroy() {
        mMapView.onDestroy()
        super.onDestroy()
    }
 
    override fun onResult(p0: SHARE_MEDIA?) {
    }
 
    override fun onCancel(p0: SHARE_MEDIA?) {
    }
 
    override fun onError(p0: SHARE_MEDIA?, p1: Throwable?) {
    }
 
    override fun onStart(p0: SHARE_MEDIA?) {
    }
}