Commit a5026e55 authored by fengruiyu's avatar fengruiyu

热门景点弹出框点击之后回调到google地图功能已完成

parent 9efbbe1d
......@@ -8,17 +8,21 @@ import com.blankj.utilcode.util.ActivityUtils.startActivity
import com.bumptech.glide.Glide
import com.fry.base.adapter.AbstractVLayoutBaseAdapter
import com.fry.base.adapter.BindingViewHolder
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.mints.street.R
import com.mints.street.bean.HotViewBean
import com.mints.street.databinding.ItemHotViewAdapterBinding
import com.mints.street.main.home.HomeViewModel
import com.mints.street.main.my.OpenvipActivity
import com.mints.street.manager.UserManager
import com.mints.street.widget.dialog.HotViewDialog
import me.goldze.mvvmhabit.utils.RxUtils
import java.text.DecimalFormat
class ItemHotViewAdapter(val context: Context, var list: List<HotViewBean.dataslist>?, val viewModel: HomeViewModel, val mCurrentLat: Double, val mCurrentLon: Double) :
AbstractVLayoutBaseAdapter<ItemHotViewAdapterBinding, List<HotViewBean.dataslist>?>(
class ItemHotViewAdapter(val context: Context, val dialog: BottomSheetDialog?, var list: List<HotViewBean.Dataslist>?,
val viewModel: HomeViewModel, val mCurrentLat: Double,
val mCurrentLon: Double, val onHotItemClick: HotViewDialog.OnHotItemClick?=null) :
AbstractVLayoutBaseAdapter<ItemHotViewAdapterBinding, List<HotViewBean.Dataslist>?>(
context, list, 1
) {
override fun onBindViewHolder(holder: BindingViewHolder<ItemHotViewAdapterBinding>, position: Int) {
......@@ -43,7 +47,8 @@ class ItemHotViewAdapter(val context: Context, var list: List<HotViewBean.datasl
//否-跳转到开通vip界面
startActivity(OpenvipActivity::class.java)
} else {
viewModel.authorized(list?.get(position)?.name, list?.get(position)?.lat, list?.get(position)?.lng)
dialog?.dismiss()
onHotItemClick?.onItemClick(position, list?.get(position))
}
}
}
......
......@@ -3,9 +3,9 @@ package com.mints.street.bean
import java.io.Serializable
class HotViewBean : Serializable {
val list: List<dataslist>? = null
public val list: List<Dataslist>? = null
inner class dataslist : Serializable {
inner class Dataslist : Serializable {
val desc: String? = null
val img: String? = null
val lat: String? = null
......
......@@ -20,6 +20,7 @@ import com.lxj.xpopup.interfaces.OnConfirmListener
import com.mints.street.BR
import com.mints.street.R
import com.mints.street.bean.GPS
import com.mints.street.bean.HotViewBean
import com.mints.street.bean.MutualBean
import com.mints.street.databinding.ActivityGoogleMapBinding
import com.mints.street.main.home.HomeViewModel
......@@ -183,7 +184,28 @@ class GoogleMapFragment() : BaseFragment<ActivityGoogleMapBinding, HomeViewModel
} //点击热门景点
RxUtils.onMultiClick(binding.lyHotview) {
HotViewDialog(requireActivity(), viewModel, 0.0, 0.0, this@GoogleMapFragment).init()
HotViewDialog(requireActivity(), viewModel,
0.0, 0.0,
this@GoogleMapFragment,object :HotViewDialog.OnHotItemClick{
override fun onItemClick(position: Int, itemBean: HotViewBean.Dataslist?) {
itemBean?.apply {
//todo 冯瑞雨 修改toDouble
viewModel.authorized(name,lat,
lng, false)
binding.webview.callHandler("initZsMap"
,Gson().toJson(GPS(lat?.toDouble()?:0.0,
lng?.toDouble()?:0.0,0)) ) {
}
}
}
}).init()
.show()
}
......@@ -249,10 +271,10 @@ class GoogleMapFragment() : BaseFragment<ActivityGoogleMapBinding, HomeViewModel
super.initViewObservable()
viewModel.authorizedBean.observe(this, Observer {
it?.apply {
// binding.webview.loadUrl("file:///android_asset/web/zsmap.html?u=${u
// }&gk=${gk}&bk=${bk}&base=${base}&ut=${ut}")
binding.webview.loadUrl("http://192.168.110.7:9999/z/zsmap.html?u=${u
binding.webview.loadUrl("file:///android_asset/web/zsmap.html?u=${u
}&gk=${gk}&bk=${bk}&base=${base}&ut=${ut}")
// binding.webview.loadUrl("http://192.168.110.7:9999/z/zsmap.html?u=${u
// }&gk=${gk}&bk=${bk}&base=${base}&ut=${ut}")
}
})
viewModel.pt.observe(this, Observer {
......
......@@ -26,7 +26,9 @@ import com.mints.street.R
import com.mints.street.bean.MapBean
import com.mints.street.bean.PositioningBean
import com.mints.street.databinding.FragmentHomeBinding
import com.mints.street.main.my.OpenvipActivity
import com.mints.street.manager.UmengManager
import com.mints.street.manager.UserManager
import com.mints.street.widget.ScrollLayout
import com.mints.street.widget.dialog.DialogMapStyle
import com.mints.street.widget.dialog.DialogUtils
......@@ -44,7 +46,13 @@ import me.goldze.mvvmhabit.utils.SPUtils
*/
class HomeFragment() : BaseFragment<FragmentHomeBinding, HomeViewModel>(), SensorEventListener {
private val viewrecommedDialog by lazy { ViewRecommedDialog(requireActivity(), viewModel, this).init() }
private val viewrecommedDialog by lazy {
ViewRecommedDialog(
requireActivity(),
viewModel,
this
).init()
}
companion object {
val IS_FIRST_OPEN: String = "isFirstOpen"
......@@ -96,9 +104,9 @@ class HomeFragment() : BaseFragment<FragmentHomeBinding, HomeViewModel>(), Senso
override fun initContentView(
inflater: LayoutInflater?,
container: ViewGroup?,
savedInstanceState: Bundle?
inflater: LayoutInflater?,
container: ViewGroup?,
savedInstanceState: Bundle?
) = R.layout.fragment_home
override fun initVariableId() = BR.viewModel
......@@ -127,9 +135,9 @@ class HomeFragment() : BaseFragment<FragmentHomeBinding, HomeViewModel>(), Senso
}
RxUtils.onMultiClick(binding.ivClick) {
viewModel.authorized(
"",
currentLat.toString(), currentLon.toString(),
false
"",
currentLat.toString(), currentLon.toString(),
false
)
}
RxUtils.onMultiClick(binding.imageMapChangeIcon) {
......@@ -145,7 +153,13 @@ class HomeFragment() : BaseFragment<FragmentHomeBinding, HomeViewModel>(), Senso
}
//点击热门景点
RxUtils.onMultiClick(binding.lyHotview) {
HotViewDialog(requireActivity(), viewModel, currentLat, currentLon, this).init().show()
if ((!UserManager.INSTANCE.userIsLogin() || !UserManager.INSTANCE.getVipFlag())) {
startActivity(OpenvipActivity::class.java)
return@onMultiClick
}
HotViewDialog(requireActivity(), viewModel, currentLat,
currentLon, this).init().show()
}
viewModel.getMapBean()
}
......@@ -210,7 +224,10 @@ class HomeFragment() : BaseFragment<FragmentHomeBinding, HomeViewModel>(), Senso
currentLat = status?.target?.latitude ?: 0.0
currentLon = status?.target?.longitude ?: 0.0
KLog.e("zsf__", "=======移动结束=======${currentLat}================${currentLon}====================")
KLog.e(
"zsf__",
"=======移动结束=======${currentLat}================${currentLon}===================="
)
currentMapZoom = status?.zoom ?: 0f
// 发起反地理编码请求
mSearch.reverseGeoCode(ReverseGeoCodeOption().location(status?.target))
......@@ -244,7 +261,7 @@ class HomeFragment() : BaseFragment<FragmentHomeBinding, HomeViewModel>(), Senso
//定位初始化
initLocation()
// 设置比例尺控件的位置,必须在地图加载完成之后
Handler().postDelayed({ binding.bmapView.scaleControlPosition = Point(20, 60) }, 500)
Handler().postDelayed({ binding.bmapView.scaleControlPosition = Point(20, 60) }, 500)
}
......@@ -254,13 +271,13 @@ class HomeFragment() : BaseFragment<FragmentHomeBinding, HomeViewModel>(), Senso
private fun initLocation() {
// 获取传感器管理服务
mSensorManager = AppManager.getAppManager().currentActivity
.getSystemService(SENSOR_SERVICE) as SensorManager
.getSystemService(SENSOR_SERVICE) as SensorManager
mCurrentMode = MyLocationConfiguration.LocationMode.NORMAL
// 为系统的方向传感器注册监听器
mSensorManager?.registerListener(
this,
mSensorManager?.getDefaultSensor(Sensor.TYPE_ORIENTATION),
SensorManager.SENSOR_DELAY_UI
this,
mSensorManager?.getDefaultSensor(Sensor.TYPE_ORIENTATION),
SensorManager.SENSOR_DELAY_UI
)
// 开启定位图层
......@@ -307,7 +324,7 @@ class HomeFragment() : BaseFragment<FragmentHomeBinding, HomeViewModel>(), Senso
val builder = MapStatus.Builder()
builder.target(center).zoom(zoom)
val mapStatusUpdate =
MapStatusUpdateFactory.newMapStatus(builder.build())
MapStatusUpdateFactory.newMapStatus(builder.build())
showupgradevipDialog(requireContext())
// 设置地图状态
mBaiduMap?.animateMapStatus(mapStatusUpdate, 200)
......@@ -409,11 +426,11 @@ class HomeFragment() : BaseFragment<FragmentHomeBinding, HomeViewModel>(), Senso
mCurrentLon = location?.longitude ?: 0.0
mCurrentAccracy = location?.radius ?: 0f
myLocationData = MyLocationData.Builder()
.accuracy(location?.radius ?: 0f) // 设置定位数据的精度信息,单位:米
.direction(mCurrentDirection.toFloat()) // 此处设置开发者获取到的方向信息,顺时针0-360
.latitude(location?.latitude ?: 0.0)
.longitude(location?.longitude ?: 0.0)
.build()
.accuracy(location?.radius ?: 0f) // 设置定位数据的精度信息,单位:米
.direction(mCurrentDirection.toFloat()) // 此处设置开发者获取到的方向信息,顺时针0-360
.latitude(location?.latitude ?: 0.0)
.longitude(location?.longitude ?: 0.0)
.build()
this.setMyLocationData(myLocationData)
if (isFirstLoc) {
isFirstLoc = false
......@@ -429,15 +446,15 @@ class HomeFragment() : BaseFragment<FragmentHomeBinding, HomeViewModel>(), Senso
override fun onSensorChanged(sensorEvent: SensorEvent?) {
val x: Double =
sensorEvent?.values?.get(SensorManager.DATA_X)?.toDouble() ?: 0.0
sensorEvent?.values?.get(SensorManager.DATA_X)?.toDouble() ?: 0.0
if (kotlin.math.abs(x - lastX) > 1.0) {
mCurrentDirection = x.toInt()
myLocationData = MyLocationData.Builder()
.accuracy(mCurrentAccracy) // 设置定位数据的精度信息,单位:米
.direction(mCurrentDirection.toFloat()) // 此处设置开发者获取到的方向信息,顺时针0-360
.latitude(mCurrentLat)
.longitude(mCurrentLon)
.build()
.accuracy(mCurrentAccracy) // 设置定位数据的精度信息,单位:米
.direction(mCurrentDirection.toFloat()) // 此处设置开发者获取到的方向信息,顺时针0-360
.latitude(mCurrentLat)
.longitude(mCurrentLon)
.build()
mBaiduMap?.setMyLocationData(myLocationData)
}
lastX = x
......
......@@ -13,11 +13,13 @@ import com.alibaba.android.vlayout.VirtualLayoutManager
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.mints.street.R
import com.mints.street.adapter.ItemHotViewAdapter
import com.mints.street.bean.HotViewBean
import com.mints.street.main.home.HomeFragment
import com.mints.street.main.home.HomeViewModel
import com.mints.street.widget.GridItemDecoration
class HotViewDialog(context: FragmentActivity, viewModel: HomeViewModel, mCurrentLat:Double, mCurrentLon:Double,fragment: Fragment) {
class HotViewDialog(context: FragmentActivity, viewModel: HomeViewModel, mCurrentLat:Double,
mCurrentLon:Double,fragment: Fragment, val onHotItemClick: OnHotItemClick?=null) {
private var mBottomSheetDialog: BottomSheetDialog? = null
private var context: FragmentActivity
......@@ -62,7 +64,8 @@ class HotViewDialog(context: FragmentActivity, viewModel: HomeViewModel, mCurren
viewModel?.getHotView()
viewModel?.hotviewData?.observe(fragment!!, androidx.lifecycle.Observer {
if (itemHotViewAdapter == null) {
itemHotViewAdapter = ItemHotViewAdapter(context, it.list, viewModel!!,mCurrentLat!!,mCurrentLon!!)
itemHotViewAdapter = ItemHotViewAdapter(context, mBottomSheetDialog,
it.list, viewModel!!,mCurrentLat!!,mCurrentLon!!,onHotItemClick)
mAdapter?.addAdapter(itemHotViewAdapter)
}
mAdapter?.notifyDataSetChanged()
......@@ -84,6 +87,8 @@ class HotViewDialog(context: FragmentActivity, viewModel: HomeViewModel, mCurren
fun onDestroy() {
mBottomSheetDialog = null
}
interface OnHotItemClick {
fun onItemClick(position: Int,itemBean: HotViewBean.Dataslist?)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment