8.6
liugl
2020-08-06 3f55faa0a1298bc2320d1e749f0b08b25b85d671
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
package com.okgoincar.base
 
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.os.Handler
import android.os.Looper
import cn.sinata.rxnetty.netStatus.NetUtils
import cn.sinata.xldutils.utils.toast
import com.google.gson.Gson
import com.okgoincar.bean.LoginBean
import com.okgoincar.netUtls.Api
import com.okgoincar.netUtls.callNet
import com.okgoincar.netUtls.getMapByAny
import com.okgoincar.netUtls.getToken
import com.okgoincar.slab.SlabLoginActivity
import com.okgoincar.slab.SlabMainActivity
import com.okgoincar.utils.Cache.CacheKey
import com.okgoincar.utils.Cache.CacheUtil
import org.greenrobot.eventbus.EventBus
import org.jetbrains.anko.startActivity
import java.lang.Exception
 
class MoneyBroadCastReceiver : BroadcastReceiver() {
    override fun onReceive(contexts: Context?, intent: Intent?) {
        if (intent == null && contexts == null){
            toast("内容获取为空,广播接收消息错误")
            return
        }
        try {
            Handler(Looper.getMainLooper()).post {
                when(intent!!.action){
                    "wisdom.intent.action.ledLight" ->{
                        val isHeavy = intent!!.getBooleanExtra("isHeavy",true)
                        if (isHeavy){
                            callStatue(contexts!!,5) //代表让订单到进行中
                        }
                    }
 
                    "wisdom.intent.action.priceDevice" -> {
                        var price = intent.getDoubleExtra("price",0.0) //计价器价格,单位为元
                        var mileage = intent.getDoubleExtra("mileage",0.0) //里程,单位为km
                        callOver(contexts!!,price)
                    }
                }
 
 
            }
        }catch (e:Exception){
 
        }
 
    }
 
    private fun callStatue(contexts: Context,i: Int) {
        if (MyApplication.currentOrderId.isEmpty()){
            toast("没有进行中的订单,无法开始")
            return
        }
        var map = getMapByAny()
        map["orderId"] = MyApplication.currentOrderId
        map["orderType"] = MyApplication.currentOrderType
        map["state"] = i
        map["lat"] = MyApplication.getLocation().latitude
        map["lon"] = MyApplication.getLocation().longitude
        callNet(contexts, Api.process, map) {
            EventBus.getDefault().post(BaseEvent(BaseEvent.UP_TRIP))
        }
    }
 
    private fun callOver(contexts: Context,travelFee:Double){
        if (MyApplication.currentOrderId.isEmpty()){
            toast("没有进行中的订单,无法结束")
            return
        }
        var map = getMapByAny()
        map["orderId"] = MyApplication.currentOrderId
        map["orderType"] = MyApplication.currentOrderType
        map["travelFee"] = travelFee
        map["lat"] = MyApplication.getLocation().latitude
        map["lon"] = MyApplication.getLocation().longitude
        map["type"] = 1
        callNet(contexts,Api.confirmFees_,map){
            EventBus.getDefault().post(BaseEvent(BaseEvent.SURE_MONEY))
        }
 
    }
 
}