Commit 49584319 authored by 张释方's avatar 张释方

优化热门景点弹窗

parent 71ab39c9
......@@ -10,7 +10,6 @@ import com.mints.street.R
import com.mints.street.bean.VreperienceBean
import com.mints.street.databinding.ItemEnterDestinationAdapterBinding
import com.mints.street.main.vr.DetailedActivity
import me.goldze.mvvmhabit.utils.KLog
import me.goldze.mvvmhabit.utils.RxUtils
......
......@@ -2,6 +2,8 @@ package com.mints.street.adapter
import android.content.Context
import com.alibaba.android.vlayout.layout.LinearLayoutHelper
import com.baidu.mapapi.model.LatLng
import com.baidu.mapapi.utils.DistanceUtil.getDistance
import com.blankj.utilcode.util.ActivityUtils.startActivity
import com.bumptech.glide.Glide
import com.fry.base.adapter.AbstractVLayoutBaseAdapter
......@@ -9,14 +11,15 @@ import com.fry.base.adapter.BindingViewHolder
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.webview.MintsWebViewActivity
import me.goldze.mvvmhabit.utils.RxUtils
import java.text.DecimalFormat
class ItemHotViewAdapter(val context: Context, var list: List<HotViewBean.dataslist>?) :
class ItemHotViewAdapter(val context: Context, var list: List<HotViewBean.dataslist>?, val viewModel: HomeViewModel, val mCurrentLat: Double, val mCurrentLon: Double) :
AbstractVLayoutBaseAdapter<ItemHotViewAdapterBinding, List<HotViewBean.dataslist>?>(
context,list,1
context, list, 1
) {
override fun onBindViewHolder(holder: BindingViewHolder<ItemHotViewAdapterBinding>, position: Int) {
......@@ -27,26 +30,28 @@ class ItemHotViewAdapter(val context: Context, var list: List<HotViewBean.datasl
//设置图片
Glide.with(mContext).load(img).into(holder.binding.image1)
//设置名称
holder.binding.viewname.text=name
holder.binding.viewname.text = name
//设置距离
// holder.binding.tvDistance.text= distance.toString()
var distance:Double=getDistance(LatLng(lat!!.toDouble(), lng!!.toDouble()),LatLng(mCurrentLat, mCurrentLon))
holder.binding.tvDistance.text = "距离${DecimalFormat("0.00").format(distance/1000).toString()}km"
//设置景点简介
holder.binding.tvDescribe.text=desc
holder.binding.tvDescribe.text = desc
//设置点击事件
RxUtils.onMultiClick(holder.itemView){
RxUtils.onMultiClick(holder.itemView) {
//判断是否当前是否是会员,
if (!UserManager.INSTANCE.userIsLogin()){
if (!UserManager.INSTANCE.userIsLogin()) {
//否-跳转到开通vip界面
startActivity(OpenvipActivity::class.java)
}else{
//是-继续浏览,
} else {
viewModel.authorized(list?.get(position)?.name, list?.get(position)?.lat?.toDouble(), list?.get(position)?.lng?.toDouble())
}
}
}
}
override fun getItemCount() = list?.size?: 0
override fun getItemCount() = list?.size ?: 0
override fun onCreateLayoutHelper() = LinearLayoutHelper()
override fun getLayoutId(viewType: Int) = R.layout.item_hot_view_adapter
......
......@@ -11,5 +11,6 @@ class HotViewBean : Serializable {
val lat: String? = null
val lng: String? = null
val name: String? = null
val distance: Double? = null
}
}
......@@ -51,7 +51,6 @@ class MainActivity : BaseActivity<ActivityMainBinding, MainViewModel>() {
R.id.menu_home -> {
if (UserManager.INSTANCE.userIsLogin() && UserManager.INSTANCE.getVipFlag()) {
binding.mainViewpager.setCurrentItem(3, false)
} else {
binding.mainViewpager.setCurrentItem(0, false)
}
......
......@@ -42,8 +42,9 @@ import me.goldze.mvvmhabit.utils.SPUtils
* 首页页面
*/
class HomeFragment() : BaseFragment<FragmentHomeBinding, HomeViewModel>(), SensorEventListener {
private val hotViewDialog by lazy { HotViewDialog(requireActivity(),viewModel,this).init() }
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"
}
......@@ -94,9 +95,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
......@@ -116,6 +117,8 @@ class HomeFragment() : BaseFragment<FragmentHomeBinding, HomeViewModel>(), Senso
override fun initData() {
super.initData()
geoCoder()
Handler().postDelayed({ isScrollLayoutClose = true }, 2000)
RxUtils.onMultiClick(binding.stbBgSearch) {
......@@ -123,9 +126,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) {
......@@ -140,9 +143,10 @@ class HomeFragment() : BaseFragment<FragmentHomeBinding, HomeViewModel>(), Senso
}
//点击热门景点
RxUtils.onMultiClick(binding.lyHotview) {
hotViewDialog.show()
}
RxUtils.onMultiClick(binding.lyHotview, {
val hotViewDialog:HotViewDialog?=HotViewDialog(requireActivity(), viewModel, currentLat,currentLon,this)
hotViewDialog?.init()?.show()
})
viewModel.getMapBean()
}
......@@ -205,6 +209,8 @@ class HomeFragment() : BaseFragment<FragmentHomeBinding, HomeViewModel>(), Senso
KLog.a("百度map", "移动结束")
currentLat = status?.target?.latitude ?: 0.0
currentLon = status?.target?.longitude ?: 0.0
KLog.e("zsf__", "=======移动结束=======${currentLat}================${currentLon}====================")
currentMapZoom = status?.zoom ?: 0f
// 发起反地理编码请求
mSearch.reverseGeoCode(ReverseGeoCodeOption().location(status?.target))
......@@ -245,13 +251,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
)
// 开启定位图层
......@@ -298,7 +304,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)
......@@ -352,9 +358,8 @@ class HomeFragment() : BaseFragment<FragmentHomeBinding, HomeViewModel>(), Senso
/**
* 更新手势状态
*/
fun updateGesture(isMove: Boolean) {
fun updateGesture(isMove: Boolean) {
if (isMove) {
mUiSettings?.isZoomGesturesEnabled = false
} else {
......@@ -401,11 +406,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
......@@ -421,15 +426,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
......
......@@ -234,4 +234,26 @@ class HomeViewModel(application: Application) : BaseViewModel(application) {
}
)
}
fun authorized(name:String?,lat:Double?=0.0 ,lng:Double?=0.0) {
ApiModel.authorized().safeSubscribe(object
: HttpSubscribeImpl<BaseResponse<AuthorizedBean>>(
this@HomeViewModel,false
) {
override fun onBusinessSuccess(response: BaseResponse<AuthorizedBean>) {
MintsWebViewActivity.startWebView(
name,
MintsWebViewActivity.toGoogleVR(
response.result.u,
response.result.gk,
response.result.base,
lat.toString(),
lng.toString(),
response.result.ut
)
)
}
})
}
}
\ No newline at end of file
package com.mints.street.utils;
public class GetJuLiUtils {
private static final double EARTH_RADIUS = 6378137.0;
public static double getDistance(double longitude,double latitue,double longitude2,double latitue2){
double lat1 = rad(latitue);
double lat2 = rad(latitue2);
double a = lat1 - lat2;
double b = rad(longitude)-rad(longitude2);
double s = 2*Math.asin(Math.sqrt(Math.pow(Math.sin(a/2),2)+Math.cos(lat1)*Math.cos(lat2)*Math.pow(Math.sin(b/2),2)));
s=s*EARTH_RADIUS;
s=Math.round(s*10000)/10000;
return s;
}
private static double rad(double d){
return d*Math.PI/180.0;
}
}
......@@ -16,58 +16,60 @@ 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, homeFragment: HomeFragment) {
class HotViewDialog(context: FragmentActivity, viewModel: HomeViewModel, mCurrentLat:Double, mCurrentLon:Double,homeFragment: HomeFragment) {
private var mBottomSheetDialog:BottomSheetDialog?=null
private var context:FragmentActivity
private var viewModel:HomeViewModel?=null
private var homeFragment:HomeFragment?=null
private var mBottomSheetDialog: BottomSheetDialog? = null
private var context: FragmentActivity
private var viewModel: HomeViewModel? = null
private var homeFragment: HomeFragment? = null
private var mCurrentLat: Double? = null
private var mCurrentLon: Double? = null
private var vLayout: VirtualLayoutManager? = null
private var mAdapter: DelegateAdapter? = null
private var itemHotViewAdapter: ItemHotViewAdapter?=null
// private var itemHotViewAdapter: ItemEnterDestinationAdapter?=null
private var itemHotViewAdapter: ItemHotViewAdapter? = null
// private var itemHotViewAdapter: ItemEnterDestinationAdapter?=null
init {
this.context=context
this.viewModel=viewModel
this.homeFragment=homeFragment
this.context = context
this.viewModel = viewModel
this.homeFragment = homeFragment
this.mCurrentLat=mCurrentLat
this.mCurrentLon=mCurrentLon
}
//
fun init():HotViewDialog{
fun init(): HotViewDialog {
//创建弹窗
if (mBottomSheetDialog!=null) return this
mBottomSheetDialog= BottomSheetDialog(context)
val view1:View=LayoutInflater.from(context).inflate(R.layout.layout_hotview,null)
if (mBottomSheetDialog != null) return this
mBottomSheetDialog = BottomSheetDialog(context)
val view1: View = LayoutInflater.from(context).inflate(R.layout.layout_hotview, null)
mBottomSheetDialog!!.setContentView(view1)
mBottomSheetDialog!!.window!!.findViewById<View>(R.id.design_bottom_sheet).setBackgroundColor(Color.TRANSPARENT)
val iv_close:ImageView=view1.findViewById(R.id.iv_close)
val recycler_view:RecyclerView=view1.findViewById(R.id.recycler_view)
val iv_close: ImageView = view1.findViewById(R.id.iv_close)
val recycler_view: RecyclerView = view1.findViewById(R.id.recycler_view)
//添加下划线
view1.findViewById<RecyclerView>(R.id.recycler_view)
.addItemDecoration(GridItemDecoration(context, DividerItemDecoration.VERTICAL))
vLayout = VirtualLayoutManager(context!!);
mAdapter = DelegateAdapter(vLayout,false)
vLayout = VirtualLayoutManager(context!!);
mAdapter = DelegateAdapter(vLayout, false)
recycler_view.layoutManager = vLayout
recycler_view.adapter = mAdapter
// if (itemHotViewAdapter == null){
// itemHotViewAdapter = ItemHotViewAdapter(context!!, listOf("1","3","1","3","1","3","1","3"))
// mAdapter?.addAdapter(itemHotViewAdapter)
// }
// itemHotViewAdapter!!.list=listOf("1","3","1","3","1","3","1","3")
viewModel?.getHotView()
viewModel?.hotviewData?.observe(homeFragment!!, androidx.lifecycle.Observer {
if (itemHotViewAdapter == null){
itemHotViewAdapter = ItemHotViewAdapter(context!!, it.list)
if (itemHotViewAdapter == null) {
itemHotViewAdapter = ItemHotViewAdapter(context!!, it.list, viewModel!!,mCurrentLat!!,mCurrentLon!!)
mAdapter?.addAdapter(itemHotViewAdapter)
}
mAdapter?.notifyDataSetChanged()
})
iv_close.setOnClickListener{
iv_close.setOnClickListener {
mBottomSheetDialog!!.dismiss()
}
return this
}
......
......@@ -53,10 +53,11 @@
android:id="@+id/ly_hotview"
android:layout_width="35dp"
android:layout_height="35dp"
android:padding="3dp"
android:layout_marginTop="15dp"
android:src="@mipmap/icon_hotview"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/image_map_history" />
app:layout_constraintTop_toBottomOf="@id/image_map_change_icon" />
<ImageView
android:id="@+id/image_location_icon"
......
......@@ -43,6 +43,9 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:ellipsize="end"
android:maxEms="5"
android:maxLines="1"
android:text="景点名称"
android:textColor="@color/black"
android:textSize="18dp"
......@@ -54,10 +57,9 @@
android:layout_width="1dp"
android:layout_height="14dp"
android:background="@color/black"
app:layout_constraintBottom_toBottomOf="@+id/tv_distance"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="@+id/viewname"
app:layout_constraintStart_toEndOf="@+id/viewname"
app:layout_constraintTop_toTopOf="@+id/tv_distance"
app:layout_constraintTop_toTopOf="@+id/viewname"
tools:ignore="MissingConstraints" />
<TextView
......@@ -65,37 +67,46 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:text="距离"
android:text="距离1897.8km"
android:textColor="#99000000"
android:textSize="14dp"
android:textSize="12dp"
app:layout_constraintBottom_toBottomOf="@+id/viewname"
app:layout_constraintStart_toEndOf="@+id/view"
app:layout_constraintTop_toTopOf="@+id/viewname"
tools:text="距离" />
<TextView
android:id="@+id/tv_describe"
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="景点介绍。。。"
android:textColor="#99000000"
app:layout_constraintStart_toEndOf="@+id/image1"
android:layout_marginTop="5dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="@+id/image1"
app:layout_constraintStart_toStartOf="@+id/viewname"
app:layout_constraintTop_toBottomOf="@+id/viewname"
tools:text="景点介绍。。。" />
tools:ignore="MissingConstraints">
<TextView
android:id="@+id/textView5"
android:layout_width="70dp"
android:layout_height="30dp"
android:layout_marginLeft="10dp"
android:background="@drawable/shape_btn_friends_unenabled"
android:gravity="center"
android:text="看街景"
android:textColor="@color/black"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="@+id/image1"
app:layout_constraintStart_toEndOf="@+id/image1"
tools:text="看街景" />
<TextView
android:id="@+id/tv_describe"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:text="景点介绍。。。"
android:textColor="#99000000"
android:textSize="12sp" />
<TextView
android:id="@+id/textView5"
android:layout_width="100dp"
android:layout_height="30dp"
android:layout_marginLeft="10dp"
android:background="@drawable/shape_btn_friends_unenabled"
android:gravity="center"
android:text="看街景"
android:textColor="@color/black"
android:textSize="12sp" />
</androidx.appcompat.widget.LinearLayoutCompat>
</androidx.constraintlayout.widget.ConstraintLayout>
......
......@@ -8,8 +8,8 @@
android:id="@+id/iv_close"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginTop="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="5dp"
android:src="@mipmap/icon_hot_view_close"
android:layout_gravity="end"/>
......
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