package com.kuanzhai.user.ui.trip
|
|
import android.Manifest
|
import android.animation.ObjectAnimator
|
import android.app.Activity
|
import android.content.Context
|
import android.content.Intent
|
import android.content.res.Resources
|
import android.graphics.Color
|
import android.net.Uri
|
import android.os.Bundle
|
import android.util.Log
|
import android.view.View
|
import android.widget.TextView
|
import androidx.core.os.bundleOf
|
import cn.sinata.amaplib.overlay.DrivingRouteOverlay
|
import cn.sinata.xldutils.*
|
import cn.sinata.xldutils.fragment.BaseFragment
|
import cn.sinata.xldutils.rxutils.ResultException
|
import cn.sinata.xldutils.utils.*
|
import com.amap.api.location.AMapLocationClient
|
import com.amap.api.location.AMapLocationClientOption
|
import com.amap.api.maps.AMap
|
import com.amap.api.maps.CameraUpdateFactory
|
import com.amap.api.maps.TextureMapView
|
import com.amap.api.maps.model.*
|
import com.amap.api.services.core.LatLonPoint
|
import com.amap.api.services.poisearch.PoiResult
|
import com.amap.api.services.poisearch.PoiSearch
|
import com.amap.api.services.route.*
|
import com.autonavi.amap.mapcore.Inner_3dMap_location
|
import com.flyco.tablayout.listener.CustomTabEntity
|
import com.flyco.tablayout.listener.OnTabSelectListener
|
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
import com.kuanzhai.user.KuanzhaiApplication
|
import com.kuanzhai.user.R
|
import com.kuanzhai.user.network.HttpManager
|
import com.kuanzhai.user.network.requestByF
|
import com.kuanzhai.user.ui.H5Activity
|
import com.kuanzhai.user.ui.MainActivity
|
import com.kuanzhai.user.dialog.ChooseReserveTimeDialog
|
import com.kuanzhai.user.dialog.SetRedPackageDialog
|
import com.kuanzhai.user.dialog.SpecialCountDialog
|
import com.kuanzhai.user.dialog.TipDialog
|
import com.kuanzhai.user.network.entity.CarPrice
|
import com.kuanzhai.user.ui.ChooseCityActivity
|
import com.kuanzhai.user.ui.mine.EditEmergencyActivity
|
import com.kuanzhai.user.ui.mine.SetEmergencyActivity
|
import com.kuanzhai.user.utils.Const
|
import com.kuanzhai.user.utils.ScreenUtil
|
import com.kuanzhai.user.utils.event.BaseEvent
|
import com.kuanzhai.user.views.textbanner.TextBannerView
|
import com.tbruyelle.rxpermissions2.RxPermissions
|
import io.reactivex.Flowable
|
import io.reactivex.subscribers.DisposableSubscriber
|
import kotlinx.android.synthetic.main.fragment_map_trip.*
|
import kotlinx.android.synthetic.main.item_car_price.view.*
|
import kotlinx.android.synthetic.main.item_img_ads.view.*
|
import kotlinx.android.synthetic.main.layout_confirm_special.*
|
import kotlinx.android.synthetic.main.layout_confirm_taxi.*
|
import org.greenrobot.eventbus.EventBus
|
import org.greenrobot.eventbus.Subscribe
|
import org.jetbrains.anko.backgroundResource
|
import org.jetbrains.anko.imageResource
|
import org.jetbrains.anko.sdk27.coroutines.onClick
|
import org.jetbrains.anko.startActivityForResult
|
import org.jetbrains.anko.support.v4.*
|
|
class MapTripFragment : BaseFragment(), RouteSearch.OnRouteSearchListener {
|
override fun contentViewId() = R.layout.fragment_map_trip
|
|
private val mMapView by lazy {
|
find<TextureMapView>(R.id.mMapView)
|
}
|
private val aMap by lazy {
|
mMapView.map
|
}
|
private val behavior by lazy {
|
BottomSheetBehavior.from(bottom)
|
}
|
private val mainActivity by lazy {
|
activity as MainActivity
|
}
|
var type = Const.OrderType.TYPE_TAXI //默认出租车
|
private val titles = arrayOf("现在","预约","代叫")
|
private var startByChoose = false //true 通过选择出发地移动地图,false 通过手势拖动地图
|
private var startByLocal = false //true 通过复位按钮移动地图,false 通过手势拖动地图
|
|
//出发经纬度
|
private var startLon = 0.0
|
private var startLat = 0.0
|
private var startName = ""
|
//到达经纬度
|
private var endLon = 0.0
|
private var endLat = 0.0
|
private var endName = ""
|
private var orderType = 1 //订单类型(1=普通,2=预约)
|
private var substitute = 0 //是否是代下单(0:否,1:是)
|
private var tipMoney = 0 //小费金额
|
private var time = "选择时间" //预约时间
|
private var timeParam = "现在" //预约时间请求参数
|
private var name = "选乘车人" //乘车人
|
private var phone:String? = null //乘车人电话
|
|
private var carTypeId = 0 //快车/专车车型id
|
private var carTypeIndex = 0 //选中的位置
|
|
private var personCount:Int = 1 //拼车人数
|
private var rideType:Int? = null //乘车类型(1=独享,2=一口价,3=拼车)
|
|
|
override fun onFirstVisibleToUser() {
|
mMapView.onCreate(savedInstanceState)
|
EventBus.getDefault().register(this)
|
if ((activity as MainActivity).isShowCard){
|
tv_buy_card_2.visible()
|
tv_buy_card.visible()
|
}else{
|
tv_buy_card_2.gone()
|
tv_buy_card.gone()
|
}
|
getNotice()
|
getBottomAds()
|
getRxPermission {
|
initMap()
|
initLocation()
|
}
|
initTab()
|
initTab2()
|
initClick()
|
behavior.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
|
override fun onSlide(bottomSheet: View, slideOffset: Float) {
|
Log.e(Const.Tag, "slideOffset:$slideOffset")
|
if (slideOffset > 0.71f && slideOffset < 0.8) {
|
val fl = 0.8f - slideOffset
|
mainActivity.updateTipAlpha(fl / 0.09f)
|
} else if (slideOffset <= 0.71)
|
mainActivity.updateTipAlpha(1f)
|
else
|
mainActivity.updateTipAlpha(0f)
|
if (slideOffset > 0.03) {
|
ll_call.gone()
|
} else
|
ll_call.visible()
|
if (slideOffset < 0.9)
|
mainActivity.updateTitleVisibility(false, false)
|
else if (slideOffset > 0.92) {
|
mainActivity.updateTitleVisibility(true, false)
|
iv_back.imageResource = R.mipmap.close_bottom
|
}
|
}
|
|
override fun onStateChanged(bottomSheet: View, newState: Int) {
|
Log.e(Const.Tag, "newState:$newState")
|
if (newState == BottomSheetBehavior.STATE_EXPANDED) {
|
// cl_option.gone()
|
// bottom.smoothScrollTo(0,ll_ads.top)
|
} else if (newState == BottomSheetBehavior.STATE_COLLAPSED) {
|
// cl_option.visible()
|
}
|
}
|
})
|
|
//用于处理当虚拟导航栏存在时,BottomSheetBehavior窥视高度不对的问题
|
val virtualBarHeigh = ScreenUtil().getVirtualBarHeigh(activity)
|
Log.e("虚拟导航栏高度", "$virtualBarHeigh")
|
val navigationBarHeight = getNavigationBarHeight()
|
Log.e("导航栏高度", "$navigationBarHeight")
|
if (virtualBarHeigh >= getNavigationBarHeight()) //如果虚拟导航栏高度大于或等于导航栏高度,说明虚拟导航栏在显示,需要减去导航栏的高度
|
behavior.setPeekHeight(dip(260) - getNavigationBarHeight(), true)
|
else
|
behavior.setPeekHeight(dip(260), true)
|
|
}
|
|
private fun initLocation() {
|
initLocationOne(activity!!)
|
}
|
|
fun initLocationOne(context: Context) { //初始化定位
|
var mlocationClient = AMapLocationClient(context)
|
var mLocationOption = AMapLocationClientOption()
|
mlocationClient.setLocationListener{p0 ->
|
p0?.let {
|
if (!p0.city.isNullOrEmpty() && p0.city != KuanzhaiApplication.chooseCityName && !isChangeCity) {
|
isChangeCity = true
|
showChangeCity()
|
mlocationClient.stopLocation()
|
}
|
}
|
}
|
mLocationOption.isNeedAddress = true
|
mLocationOption.isOnceLocation = false
|
mLocationOption.locationMode = AMapLocationClientOption.AMapLocationMode.Hight_Accuracy
|
mlocationClient.setLocationOption(mLocationOption)
|
mlocationClient.startLocation() //启动定位
|
}
|
|
|
private fun getNavigationBarHeight(): Int {
|
val resources: Resources = activity!!.getResources()
|
val resourceId: Int = resources.getIdentifier("navigation_bar_height", "dimen", "android")
|
val height: Int = resources.getDimensionPixelSize(resourceId)
|
return height
|
}
|
|
private fun initClick() {
|
//点击归位
|
iv_location.setOnClickListener {
|
startByLocal = true
|
aMap.animateCamera(
|
CameraUpdateFactory.newLatLngZoom(
|
LatLng(
|
KuanzhaiApplication.lat,
|
KuanzhaiApplication.lon
|
), 15f
|
)
|
)
|
}
|
iv_location2.setOnClickListener {
|
drivingRouteOverlay!!.zoomToSpan(40, 120, 40, 300)
|
}
|
tv_110.setOnClickListener {
|
callPhone(mainActivity.phoneEmergency)
|
}
|
tv_service.setOnClickListener {
|
callPhone(KuanzhaiApplication.phoneService)
|
}
|
tv_start.setOnClickListener {
|
startActivityForResult<ChoosePositionActivity>(1)
|
if (behavior.state == BottomSheetBehavior.STATE_EXPANDED)
|
behavior.state = BottomSheetBehavior.STATE_COLLAPSED
|
}
|
tv_end.setOnClickListener {
|
startActivityForResult<ChoosePositionWithMapActivity>(2, "isStart" to false)
|
if (behavior.state == BottomSheetBehavior.STATE_EXPANDED)
|
behavior.state = BottomSheetBehavior.STATE_COLLAPSED
|
}
|
tv_time.setOnClickListener {
|
showTimeDialog()
|
}
|
tv_option.setOnClickListener {
|
if (tab_type.currentTab == 1) {
|
showTimeDialog()
|
} else {//代叫
|
startActivityForResult<OrderOtherActivity>(3)
|
}
|
}
|
tv_time_special.onClick {
|
showTimeDialog()
|
}
|
|
tv_passenger.setOnClickListener {
|
startActivityForResult<OrderOtherActivity>(3)
|
}
|
|
tv_passenger_special.onClick {
|
startActivityForResult<OrderOtherActivity>(3)
|
}
|
|
tv_retry.onClick {
|
getCarType()
|
}
|
|
tv_tips.setOnClickListener {
|
val setRedPackageDialog = SetRedPackageDialog()
|
setRedPackageDialog.setCallback(object : SetRedPackageDialog.Callback {
|
override fun onOk(int: Int) {
|
tipMoney = int
|
tv_tips.text = String.format("小费%d元", tipMoney)
|
}
|
})
|
setRedPackageDialog.show(fragmentManager!!, "red")
|
}
|
|
iv_back.setOnClickListener {
|
if (behavior.state == BottomSheetBehavior.STATE_EXPANDED) {
|
behavior.state = BottomSheetBehavior.STATE_COLLAPSED
|
bottom.smoothScrollTo(0, 0)
|
} else {
|
back()
|
}
|
}
|
|
tv_set_emergency.onClick {
|
setEmergency()
|
}
|
|
tv_emergency_special.onClick {
|
setEmergency()
|
}
|
|
tv_action_taxi.setOnClickListener {
|
makeOrder()
|
}
|
|
cl_pin.setOnClickListener {
|
if (personCount == 4){
|
myToast("拼车人数必须小于4")
|
return@setOnClickListener
|
}
|
iv_check_pin.imageResource = R.mipmap.check
|
iv_check_privacy.imageResource = R.mipmap.check_gray
|
iv_check_one.imageResource = R.mipmap.check_gray
|
rideType = 3
|
tv_action_special.text = "呼叫拼车"
|
}
|
cl_privacy.setOnClickListener {
|
iv_check_pin.imageResource = R.mipmap.check_gray
|
iv_check_privacy.imageResource = R.mipmap.check
|
iv_check_one.imageResource = R.mipmap.check_gray
|
rideType = 1
|
tv_action_special.text = "呼叫快车/专车"
|
}
|
cl_one.setOnClickListener {
|
iv_check_pin.imageResource = R.mipmap.check_gray
|
iv_check_privacy.imageResource = R.mipmap.check_gray
|
iv_check_one.imageResource = R.mipmap.check
|
rideType = 2
|
tv_action_special.text = "呼叫快车/专车"
|
}
|
tv_count_special.setOnClickListener {
|
val specialCountDialog = SpecialCountDialog()
|
specialCountDialog.arguments = bundleOf("count" to personCount)
|
specialCountDialog.setCallback(object :SpecialCountDialog.Callback{
|
override fun onOk(num: Int) {
|
personCount = num
|
tv_count_special.text = "${num}人"
|
if (num == 4){
|
cl_privacy.callOnClick()
|
}
|
refreshSpecialPrice()
|
}
|
})
|
specialCountDialog.show(childFragmentManager,"count")
|
}
|
|
tv_action_special.setOnClickListener {
|
when {
|
carTypeIndex == -1 -> myToast("请选择车型")
|
rideType == null -> myToast("请选择乘车类型")
|
personCount == null&&rideType == 3 -> {
|
val specialCountDialog = SpecialCountDialog()
|
specialCountDialog.setCallback(object :SpecialCountDialog.Callback{
|
override fun onOk(num: Int) {
|
personCount = num
|
tv_count_special.text = "${num}人"
|
if (num == 4&&rideType == 3){ //4人不可拼车
|
cl_privacy.callOnClick()
|
}
|
makeOrder()
|
}
|
})
|
specialCountDialog.show(childFragmentManager,"count")
|
}
|
else -> makeOrder()
|
}
|
}
|
|
tv_buy_card.setOnClickListener {
|
if ((activity as MainActivity).checkLogin()){
|
startActivity<BuyCardActivity>("type" to type)
|
}
|
}
|
tv_buy_card_2.setOnClickListener {
|
if ((activity as MainActivity).checkLogin()){
|
startActivity<BuyCardActivity>()
|
}
|
}
|
}
|
|
private fun makeOrder() {
|
if (mainActivity.checkLogin() && mainActivity.checkPhone()) {
|
if (KuanzhaiApplication.emergency.isEmpty()) {
|
myToast("请设置紧急联系人")
|
startActivity<SetEmergencyActivity>(
|
"name" to "no",
|
"phone" to "",
|
"myPhone" to mainActivity.userInfo!!.phone
|
)
|
return
|
}
|
orderType = if (type == Const.OrderType.TYPE_TAXI) { //出租车预约判断多一个tab选择为1的条件
|
if (tab_confirm.currentTab == 1 && (time != "选择时间" && time != "现在")) 2 else 1
|
} else {//快车/专车预约只需要判断是否选择时间
|
if ((time != "选择时间" && time != "现在")) 2 else 1
|
}
|
substitute = if (type == Const.OrderType.TYPE_TAXI) { //出租车代叫判断tab选择为2
|
if (tab_confirm.currentTab == 2) 1 else 0
|
} else {//快车/专车代叫只判断是否选择姓名
|
if (name != "选乘车人") 1 else 0
|
}
|
tv_action_taxi.isClickable = false
|
tv_action_special.isClickable = false
|
showDialog()
|
HttpManager.addTaxiOrder(
|
endName,
|
endLat,
|
endLon,
|
1,
|
orderType,
|
KuanzhaiApplication.lat,
|
KuanzhaiApplication.lon,
|
startName,
|
startLat,
|
startLon,
|
substitute,
|
tipMoney,
|
if (orderType == 1) System.currentTimeMillis().toTime("yyyy-MM-dd HH:mm")
|
else timeParam,
|
null,
|
if (substitute == 0) null else name,
|
if (substitute == 0) null else phone,
|
carTypeId,rideType,personCount, 1, type
|
).requestByF(this, success = { _, data ->
|
data?.run {
|
tv_action_taxi.isClickable = true
|
tv_action_special.isClickable = true
|
startActivity<TripActivity>("type" to type, "id" to optInt("id"))
|
back()
|
}
|
}, error = { _, _ ->
|
tv_action_taxi.isClickable = true
|
tv_action_special.isClickable = true
|
})
|
}
|
}
|
|
private fun setEmergency() {
|
if (mainActivity.checkLogin()) {
|
if (mainActivity.userInfo?.emergencyContactNumber.isNullOrEmpty())
|
startActivity<SetEmergencyActivity>(
|
"name" to "",
|
"phone" to "", "myPhone" to mainActivity.userInfo?.phone
|
)
|
else
|
startActivity<EditEmergencyActivity>(
|
"name" to mainActivity.userInfo?.emergencyContact,
|
"phone" to mainActivity.userInfo?.emergencyContactNumber,
|
"myPhone" to mainActivity.userInfo?.phone
|
)
|
}
|
}
|
|
private fun showTimeDialog() {
|
val chooseReserveTimeDialog = ChooseReserveTimeDialog()
|
chooseReserveTimeDialog.setCallback(object : ChooseReserveTimeDialog.Callback {
|
override fun onOk(s: String, formatS: String) {
|
tv_time.text = s
|
tv_option.text = s
|
tv_time_special.text = s
|
time = s
|
timeParam = formatS
|
}
|
})
|
chooseReserveTimeDialog.show(fragmentManager!!, "time")
|
}
|
|
fun getRxPermission(function: () -> Unit) {
|
val disposable =
|
RxPermissions(activity!!).request(Manifest.permission.ACCESS_FINE_LOCATION)
|
.subscribe {
|
if (it) {
|
function()
|
} else {
|
function()
|
// myToast("没有定位权限")
|
}
|
}
|
onBindHelper(disposable)
|
}
|
|
private var locCount = 0L //定位次数
|
private var isChangeCity = false
|
private fun initMap() {
|
val myLocationStyle = MyLocationStyle()
|
myLocationStyle.strokeColor(resources.getColor(R.color.colorBrown))
|
myLocationStyle.radiusFillColor(resources.getColor(R.color.colorTransBrown))
|
myLocationStyle.interval(3000)
|
myLocationStyle.anchor(0.5f, 0.5f)
|
myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE_NO_CENTER)//
|
myLocationStyle.myLocationIcon(BitmapDescriptorFactory.fromResource(R.mipmap.icon_coordinate))
|
aMap.myLocationStyle = myLocationStyle//设置定位蓝点的Style
|
aMap.uiSettings.isMyLocationButtonEnabled = false//设置默认定位按钮是否显示,非必需设置。
|
aMap.uiSettings.setZoomInByScreenCenter(true)
|
aMap.uiSettings.isZoomControlsEnabled = false
|
aMap.uiSettings.isRotateGesturesEnabled = false
|
aMap.uiSettings.isTiltGesturesEnabled = false
|
aMap.isMyLocationEnabled = true
|
aMap.setOnMyLocationChangeListener {
|
it as Inner_3dMap_location
|
Log.e(Const.Tag, "出租车:lat:" + it.latitude + ",lon:" + it.longitude)
|
KuanzhaiApplication.lat = it.latitude
|
KuanzhaiApplication.lon = it.longitude
|
KuanzhaiApplication.address = it.address
|
KuanzhaiApplication.cityCode = it.extras.getString("adcode") ?: ""
|
if (locCount < 1) {
|
if (mainActivity.lat != 0.0)
|
aMap.animateCamera(
|
CameraUpdateFactory.newLatLngZoom(
|
LatLng(
|
mainActivity.lat,
|
mainActivity.lon
|
), 15f
|
)
|
)
|
else
|
aMap.animateCamera(
|
CameraUpdateFactory.newLatLngZoom(
|
LatLng(
|
it.latitude,
|
it.longitude
|
), 15f
|
)
|
)
|
}
|
locCount++
|
}
|
aMap.setOnCameraChangeListener(object : AMap.OnCameraChangeListener {
|
override fun onCameraChangeFinish(p0: CameraPosition?) {
|
if (!startByChoose && iv_center.visibility == View.VISIBLE) {
|
startLat = p0?.target?.latitude ?: 0.0
|
startLon = p0?.target?.longitude ?: 0.0
|
getPoi(startLat, startLon)
|
}
|
startByChoose = false
|
startByLocal = false
|
val objectAnimator =
|
ObjectAnimator.ofFloat(iv_center, "translationY", 0f, -30f, 0f).setDuration(600)
|
val objectAnimator1 =
|
ObjectAnimator.ofFloat(tv_msg, "translationY", 0f, -30f, 0f).setDuration(600)
|
objectAnimator.start()
|
objectAnimator1.start()
|
if (endLat == 0.0)
|
getDriverNum()
|
tv_msg.text = "在这里上车"
|
}
|
|
override fun onCameraChange(p0: CameraPosition?) {
|
if (startByLocal)
|
tv_msg.text = "正在获取定位"
|
else if (!startByChoose)
|
tv_msg.text = "拖到路边,接驾更快"
|
}
|
})
|
}
|
|
private fun showChangeCity() {
|
val tipDialog = TipDialog()
|
tipDialog.arguments = bundleOf("msg" to "当前城市与定位城市不符,是否切换?")
|
tipDialog.setCallback(object : TipDialog.OnClickCallback {
|
override fun onOk() {
|
activity!!.startActivityForResult<ChooseCityActivity>(501)
|
}
|
|
override fun onCancel() {
|
|
}
|
})
|
tipDialog.show(childFragmentManager, "clear")
|
}
|
|
private fun initTab() {
|
val list = arrayListOf<CustomTabEntity>()
|
list.addAll(titles.map {
|
object : CustomTabEntity {
|
override fun getTabUnselectedIcon() = 0
|
|
override fun getTabSelectedIcon() = 0
|
|
override fun getTabTitle() = it
|
}
|
})
|
tab_type.setTabData(list)
|
tab_type.currentTab = 0
|
tab_type.setOnTabSelectListener(object : OnTabSelectListener {
|
override fun onTabSelect(position: Int) {
|
tv_option.visibility = if (position == 0) View.GONE else View.VISIBLE
|
tv_option.text = if (position == 1) time else name
|
tv_time_special.text = if (position == 1) "选择时间" else "现在"
|
}
|
|
override fun onTabReselect(position: Int) {
|
}
|
})
|
}
|
|
private fun initTab2() {
|
val list = arrayListOf<CustomTabEntity>()
|
list.addAll(titles.map {
|
object : CustomTabEntity {
|
override fun getTabUnselectedIcon() = 0
|
|
override fun getTabSelectedIcon() = 0
|
|
override fun getTabTitle() = it
|
}
|
})
|
tab_confirm.setTabData(list)
|
tab_confirm.currentTab = 0
|
tab_confirm.setOnTabSelectListener(object : OnTabSelectListener {
|
override fun onTabSelect(position: Int) {
|
if (position == 1) {
|
tv_time.visible()
|
vertical_1.visible()
|
} else {
|
tv_time.gone()
|
vertical_1.gone()
|
}
|
}
|
|
override fun onTabReselect(position: Int) {
|
}
|
})
|
}
|
|
fun changeType(type: Int) {
|
this.type = type
|
getDriverNum()
|
checkBack()
|
}
|
|
fun getDriverNum() {
|
if (activity == null)
|
return
|
if (!mainActivity?.isTripping && startLat != 0.0)
|
HttpManager.getDriverNum(startLat, startLon, type).requestByF(this,false) { _, data ->
|
mainActivity.updateTipText("当前附近有${data?.optInt("number") ?: 0}辆车可用")
|
}
|
}
|
|
|
private fun getNotice() {
|
HttpManager.queryNotices(1).requestByF(this) { _, data ->
|
data?.let {
|
val list = arrayListOf<String>()
|
list.addAll(it.map {
|
it.content
|
})
|
(textBanner as TextBannerView<String>).setDatas(list)
|
(textBanner2 as TextBannerView<String>).setDatas(list)
|
}
|
}
|
}
|
|
/**
|
* 底部广告
|
*/
|
private fun getBottomAds() {
|
if (mainActivity.isOpen)
|
HttpManager.getAds(2, KuanzhaiApplication.chooseCityCode).requestByF(this,false) { _, data ->
|
data?.let {
|
it.forEach {
|
val view = layoutInflater.inflate(R.layout.item_img_ads, null)
|
view.iv_img.setImageURI(it.imgUrl)
|
view.iv_img.setOnClickListener { _ ->
|
if (it.isJump == 1) { //要跳转
|
if (it.jumpType == "2")
|
startActivity<H5Activity>(
|
"title" to it.name,
|
"url" to it.content
|
)
|
else {
|
val intent = Intent()
|
intent.action = "android.intent.action.VIEW"
|
intent.data = Uri.parse(it.jumpUrl)
|
startActivity(intent)
|
}
|
}
|
}
|
ll_ads.addView(view)
|
}
|
}
|
}
|
}
|
|
|
/**
|
*查询快车/专车类型和价格
|
*/
|
private var nowCarType:CarPrice? = null
|
private fun getCarType() {
|
showDialog()
|
HttpManager.queryServerCarModel("$startLon,$startLat", "$endLon,$endLat", type)
|
.requestByF(this, success = { _, data ->
|
data?.let { list ->
|
if (list.isEmpty()) {
|
tv_empty.visible()
|
tv_action_special.isEnabled = false
|
} else {
|
tv_action_special.isEnabled = true
|
tv_error.gone()
|
tv_retry.gone()
|
list.forEachIndexed { index, it ->
|
val view =
|
layoutInflater.inflate(R.layout.item_car_price, ll_type, false)
|
view.tv_name.text = it.name
|
// view.tv_price.text = String.format("预估%.2f", it.amount)
|
view.iv_car.setImageURI(it.img)
|
if (index == 0){ //母贝:2022.6.7 默认选中第一项
|
carTypeId = it.id
|
view.tv_name.isChecked = true
|
view.tv_price.isChecked = true
|
view.ll_car.elevation = dip(3).toFloat()
|
view.ll_car.backgroundResource = R.drawable.bg_white_6dp
|
nowCarType = it
|
refreshSpecialPrice()
|
}
|
view.onClick { _ ->
|
if (index != carTypeIndex) {
|
view.tv_name.isChecked = true
|
view.tv_price.isChecked = true
|
view.ll_car.elevation = dip(5).toFloat()
|
view.ll_car.backgroundResource = R.drawable.bg_white_6dp
|
if (carTypeIndex != -1)
|
ll_type.getChildAt(carTypeIndex).apply {
|
tv_name.isChecked = false
|
tv_price.isChecked = false
|
ll_car.elevation = 0f
|
ll_car.backgroundResource = 0
|
}
|
carTypeIndex = index
|
carTypeId = it.id
|
nowCarType = it
|
refreshSpecialPrice()
|
}
|
}
|
ll_type.addView(view)
|
}
|
}
|
tv_failed_money.clickDelay {
|
startActivity<PinPriceRuleActivity>("describe" to list[carTypeIndex].fareTypeNote1,"rule" to list[carTypeIndex])
|
}
|
tv_price_privacy.clickDelay {
|
startActivity<PriceRuleActivity>("title" to "独享","describe" to list[carTypeIndex].fareTypeNote2,
|
"rule" to list[carTypeIndex].contentExclusive)
|
}
|
tv_price_one.clickDelay {
|
startActivity<PriceRuleActivity>("title" to "一口价","describe" to list[carTypeIndex].fareTypeNote3,
|
"rule" to list[carTypeIndex].contentPrice)
|
}
|
}
|
}) { _, _ ->
|
tv_error.visible()
|
tv_retry.visible()
|
tv_action_special.isEnabled = false
|
}
|
}
|
|
/**
|
* 快车/专车根据选择的车型渲染价格
|
* @param price:选择的车型价格数据
|
*/
|
private fun refreshSpecialPrice(){
|
cl_pin.visibility = if (nowCarType?.isOpen == 1){
|
val s1 = "未拼成预估%.2f元".format(nowCarType?.getPricePinFailed(personCount))
|
tv_failed_money.text = SpanBuilder(s1).size(5,s1.length-1,14)
|
.color(requireContext(),5,s1.length-1,R.color.textColor)
|
.bold(5,s1.length-1).build()
|
val s2 = "拼成价%.2f元".format(nowCarType?.getPricePin(personCount))
|
tv_price_pin.text = SpanBuilder(s2).size(3,s2.length-1,14)
|
.color(requireContext(),3,s2.length-1,R.color.textColor)
|
.bold(3,s2.length-1).build()
|
View.VISIBLE
|
}else View.GONE
|
cl_privacy.visibility = if (nowCarType?.isOpenExclusive == 1){
|
val s1 = "预估%.2f元".format(nowCarType?.amount)
|
tv_price_privacy.text = SpanBuilder(s1).size(2,s1.length-1,14)
|
.color(requireContext(),2,s1.length-1,R.color.textColor)
|
.bold(2,s1.length-1).build()
|
View.VISIBLE
|
}else View.GONE
|
cl_one.visibility = if (nowCarType?.isOpenPrice == 1){
|
val s1 = "一口价%.2f元".format(nowCarType?.buyNowAmount)
|
tv_price_one.text = SpanBuilder(s1).size(3,s1.length-1,14)
|
.color(requireContext(),3,s1.length-1,R.color.textColor)
|
.bold(3,s1.length-1).build()
|
View.VISIBLE
|
}else View.GONE
|
}
|
|
/**
|
* 获取poi信息
|
*/
|
private var poiSearchDisposable: DisposableSubscriber<PoiResult>? = null
|
|
fun getPoi(lat: Double?, lng: Double?) {
|
if (lat == null || lng == null) {
|
return
|
}
|
//如果上一次还没处理完,取消订阅
|
if (poiSearchDisposable != null && !poiSearchDisposable!!.isDisposed) {
|
poiSearchDisposable?.dispose()
|
}
|
poiSearchDisposable = object : DisposableSubscriber<PoiResult>() {
|
override fun onComplete() {
|
|
}
|
|
override fun onNext(t: PoiResult?) {
|
val address = if (t != null) {
|
t.pois.sortBy { it.distance }
|
if (t.pois.isNotEmpty()) {
|
t.pois[0].title
|
} else {
|
null
|
}
|
} else {
|
null
|
}
|
runOnUiThread {
|
startName = address ?: ""
|
tv_start?.text = address
|
mainActivity.startName = startName
|
mainActivity.startLat = startLat
|
mainActivity.startLon = startLon
|
}
|
}
|
|
override fun onError(t: Throwable?) {
|
runOnUiThread {
|
startName = ""
|
tv_start.text = "点击选择起点"
|
}
|
}
|
}
|
val query = PoiSearch.Query("", "190000", "")
|
val poiSearch = PoiSearch(context, query)
|
poiSearch.bound = PoiSearch.SearchBound(LatLonPoint(lat, lng), 1000)
|
Flowable.just(poiSearch).ioScheduler().flatMap {
|
try {
|
val result = poiSearch.searchPOI()
|
if (result == null) {
|
Flowable.error(ResultException(""))
|
} else
|
Flowable.just(result)
|
} catch (e: Exception) {
|
e.printStackTrace()
|
Flowable.error<PoiResult>(e)
|
}
|
}.subscribe(poiSearchDisposable)
|
}
|
|
private fun searchRoute(start: LatLonPoint, end: LatLonPoint) {
|
val fromAndTo = RouteSearch.FromAndTo(start, end)
|
val driveRouteQuery =
|
RouteSearch.DriveRouteQuery(fromAndTo, RouteSearch.DrivingDefault, null, null, "")
|
val routeSearch = RouteSearch(mainActivity)
|
routeSearch.calculateDriveRouteAsyn(driveRouteQuery)
|
routeSearch.setRouteSearchListener(this)
|
}
|
|
/**确认订单*/
|
private fun showConfirmOrder() {
|
if (endLat != 0.0 && endLon != 0.0) {
|
iv_center.gone()
|
tv_msg.gone()
|
searchRoute(LatLonPoint(startLat, startLon), LatLonPoint(endLat, endLon))
|
bottom.gone()
|
cl_bottom.visible()
|
iv_location2.visible()
|
textBanner2.visible()
|
iv_banner2.visible()
|
tab_confirm.currentTab = tab_type.currentTab
|
tv_time.visibility = if (tab_confirm.currentTab == 1) View.VISIBLE else View.GONE
|
vertical_1.visibility = tv_time.visibility
|
mainActivity.updateTitleVisibility(false, true)
|
iv_back.imageResource = R.mipmap.back
|
setMarker(LatLng(startLat, startLon))
|
when (type) { //根据订单类型渲染
|
Const.OrderType.TYPE_SPECIAL -> {
|
// mainActivity.updateTipAlpha(0f)
|
cl_special.visible()
|
getCarType()
|
}
|
Const.OrderType.TYPE_TAXI -> {
|
cl_taxi.visible()
|
}
|
}
|
}
|
}
|
|
/**检查返回状态*/
|
fun checkBack(): Boolean {
|
if (!isAdded)
|
return false
|
return if (cl_bottom.visibility == View.VISIBLE) { //先返回到上一步
|
back()
|
false
|
} else
|
true
|
}
|
|
/**返回上一步*/
|
fun back() {
|
cl_bottom.gone()
|
bottom.visible()
|
iv_location2.gone()
|
iv_banner2.gone()
|
textBanner2.gone()
|
iv_center.visible()
|
mainActivity.updateTitleVisibility(false, false)
|
mainActivity.updateTipAlpha(1f)
|
drivingRouteOverlay?.removeFromMap()
|
startMarker?.remove()
|
endMarker?.remove()
|
endLat = 0.0
|
endLon = 0.0
|
time = "选择时间"
|
phone = ""
|
name = "选乘车人"
|
startByLocal = true
|
aMap.animateCamera(
|
CameraUpdateFactory.newLatLngZoom(
|
LatLng(
|
KuanzhaiApplication.lat,
|
KuanzhaiApplication.lon
|
), 15f
|
)
|
)
|
|
//出租车重置
|
cl_taxi.gone()
|
tipMoney = 0
|
tv_time.text = "预约时间"
|
tv_passenger.text = "更换乘车人"
|
tv_tips.text = "小费"
|
tab_type.currentTab = 0
|
|
//快车/专车重置
|
cl_special.gone()
|
tv_time_special.text = "现在"
|
tv_passenger_special.text = "选乘车人"
|
tv_count_special.text = "1人"
|
carTypeIndex = 0
|
carTypeId = 0
|
rideType = null
|
personCount = 1
|
iv_check_pin.imageResource = R.mipmap.check_gray
|
iv_check_privacy.imageResource = R.mipmap.check_gray
|
iv_check_one.imageResource = R.mipmap.check_gray
|
ll_type.removeAllViews()
|
tv_option.gone()
|
tv_msg.visible()
|
tv_empty.gone()
|
tv_error.gone()
|
tv_retry.gone()
|
tv_action_special.isEnabled = true
|
}
|
|
@Subscribe
|
fun onEvent(e:BaseEvent){
|
if (e.type == Const.Event.EVENT_CARD_SHOW){
|
if (e.obj as Boolean){
|
tv_buy_card_2.visible()
|
tv_buy_card.visible()
|
}else{
|
tv_buy_card_2.gone()
|
tv_buy_card.gone()
|
}
|
}
|
}
|
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
super.onActivityResult(requestCode, resultCode, data)
|
if (resultCode == Activity.RESULT_OK && data != null) {
|
when (requestCode) {
|
1 -> {
|
startLat = data.getDoubleExtra("lat", 0.0)
|
startLon = data.getDoubleExtra("lon", 0.0)
|
startByChoose = true
|
aMap.animateCamera(CameraUpdateFactory.newLatLng(LatLng(startLat, startLon)))
|
startName = data.getStringExtra("name") ?: ""
|
tv_start.text = startName
|
showConfirmOrder()
|
}
|
2 -> {
|
endLat = data.getDoubleExtra("lat", 0.0)
|
endLon = data.getDoubleExtra("lon", 0.0)
|
endName = data.getStringExtra("name") ?: ""
|
showConfirmOrder()
|
}
|
3 -> {
|
name = data.getStringExtra("name") ?: ""
|
phone = data.getStringExtra("phone") ?: ""
|
tv_option.text = name
|
tv_passenger.text = name
|
tv_passenger_special.text = name
|
}
|
}
|
}
|
}
|
|
private var startMarker: Marker? = null
|
private var endMarker: Marker? = null
|
private fun setMarker(latLon: LatLng, content: String = "") {
|
val options = MarkerOptions()
|
options.position(latLon)
|
if (content.isNotEmpty()) {
|
val view = layoutInflater.inflate(R.layout.marker_with_text, null, false)
|
val contentView = view.findViewById(R.id.tv_content) as TextView
|
contentView.text = SpanBuilder(content).color(
|
mainActivity,
|
4,
|
content.length - 2,
|
R.color.colorPrimary
|
).build()
|
options.icon(BitmapDescriptorFactory.fromView(view))
|
startMarker = aMap.addMarker(options)
|
} else {
|
options.icon(BitmapDescriptorFactory.fromResource(R.mipmap.starting_point))
|
endMarker = aMap.addMarker(options)
|
}
|
}
|
|
private var drivingRouteOverlay: DrivingRouteOverlay? = null
|
override fun onDriveRouteSearched(result: DriveRouteResult?, errorCode: Int) {
|
if (errorCode == 1000) {
|
drivingRouteOverlay?.removeFromMap()
|
if (result?.paths != null) {
|
if (result.paths.size > 0) {
|
val drivePath = result.paths[0]
|
drivingRouteOverlay = DrivingRouteOverlay(
|
activity, aMap, drivePath,
|
result.startPos,
|
result.targetPos
|
)
|
drivingRouteOverlay!!.setNodeIconVisibility(false)
|
drivingRouteOverlay!!.addToMap(Color.parseColor("#00C47A"))
|
drivingRouteOverlay!!.zoomToSpan(40, 120, 40, 300)
|
val args = drivePath.duration / 60
|
setMarker(
|
LatLng(endLat, endLon),
|
String.format("大约行驶%d分钟", if (args == 0L) 1 else args)
|
)
|
}
|
}
|
}
|
}
|
|
override fun onBusRouteSearched(p0: BusRouteResult?, p1: Int) {
|
}
|
|
override fun onRideRouteSearched(p0: RideRouteResult?, p1: Int) {
|
}
|
|
override fun onWalkRouteSearched(p0: WalkRouteResult?, p1: Int) {
|
}
|
|
|
var savedInstanceState: Bundle? = null
|
override fun onCreate(savedInstanceState: Bundle?) {
|
super.onCreate(savedInstanceState)
|
this.savedInstanceState = savedInstanceState
|
}
|
|
override fun onResume() {
|
super.onResume()
|
mMapView.onResume()
|
}
|
|
override fun onPause() {
|
super.onPause()
|
mMapView.onPause()
|
}
|
|
override fun onDestroy() {
|
super.onDestroy()
|
mMapView.onDestroy()
|
EventBus.getDefault().unregister(this)
|
}
|
|
override fun onSaveInstanceState(outState: Bundle) {
|
super.onSaveInstanceState(outState)
|
mMapView.onSaveInstanceState(outState)
|
}
|
|
override fun onLowMemory() {
|
super.onLowMemory()
|
mMapView.onLowMemory()
|
}
|
}
|