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