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))
|
}
|
|
}
|
|
}
|