Commit c29a8e87 authored by fengruiyu's avatar fengruiyu

修改JS(z3map)

地图样式
parent 4d37bd73
......@@ -114,6 +114,16 @@ function needPay() {
}
}
function needPayPopup() {
try {
doAppFun("needPayPopup");
} catch (e) {
// console.log("tips", msg)
//alert("app未弹框==>" + msg + e)
}
}
function tips(msg) {
try {
doAppFun("tips", msg);
......
......@@ -52,7 +52,7 @@ var vm = new Vue({
vrs: function () {
var th = this;
if(this.isVip==false){
this.needPay();
this.needPay('p');
return;
}
if (th.canclick) {
......@@ -129,7 +129,7 @@ var vm = new Vue({
})
marker.addListener("click", (ss) => {
if(this.isVip==false){
this.needPay();
this.needPay('p');
return;
}
params = vm.getSeLabel(marker.getTitle());
......@@ -232,9 +232,14 @@ var vm = new Vue({
return;
}
},
needPay:function(){
needPay:function(d){
console.log("<<请开启会员")
if(d!=undefined&&d!=null&&d=='p'){
needPay();
return;
}
needPayPopup();
},
G_initMap: function (point, zoomLevel) {
if (zoomLevel == undefined || zoomLevel == null)
......@@ -284,24 +289,14 @@ var vm = new Vue({
});
G_MAP.addListener("dragend", () => {
// G_MAP.addListener("dragend", () => {
// centerChanged();
// });
document.addEventListener("touchstart", function (e) {
centerChanged();
});
// document.addEventListener("touchstart", function (e) {
// console.log(e.touches);
// if (e.touches.length > 1) {
// vm.gdcenter =
// {
// lat: G_MAP.getCenter().lat(),
// lng: G_MAP.getCenter().lng()
// };
// console.log("两指")
// } else {
// vm.gdcenter = null;
// console.log("一指")
// }
// }, false);
}, false);
}
......@@ -317,7 +312,7 @@ var vm = new Vue({
window.onload = function () {
allIsOk();
// init();
//init();
}
function init() {
......
package com.mints.street.adapter
import android.content.Context
import android.content.Intent
import android.view.View
import com.alibaba.android.vlayout.LayoutHelper
import com.alibaba.android.vlayout.layout.GridLayoutHelper
import com.alibaba.android.vlayout.layout.LinearLayoutHelper
import com.fry.base.adapter.AbstractVLayoutBaseAdapter
import com.fry.base.adapter.BindingViewHolder
import com.fry.base.utils.ImageLoader
import com.mints.street.R
import com.mints.street.bean.MapStyleList
import com.mints.street.databinding.DialogMapContentItemBinding
import com.mints.street.databinding.DialogMapContentItemBindingImpl
import com.mints.street.databinding.ItemGridMapAdapterBinding
import com.mints.street.main.my.OpenvipActivity
import com.mints.street.manager.UserManager
import me.goldze.mvvmhabit.base.AppManager
import me.goldze.mvvmhabit.utils.RxUtils
/**
* Created by 冯瑞雨 on 2021/8/9.
*/
class DialogMapContentAdapter(val context: Context, var list: List<MapStyleList>?,
val onItemMapStyleChange:OnItemMapStyleChange?=null) :
class DialogMapContentAdapter(
val context: Context, var list: List<MapStyleList>?,
private val onItemMapStyleChange: OnItemMapStyleChange? = null
) :
AbstractVLayoutBaseAdapter<DialogMapContentItemBinding, List<MapStyleList>>(context, list, 2) {
override fun onBindViewHolder(
holder: BindingViewHolder<DialogMapContentItemBinding>,
position: Int) {
when(list?.get(position)?.img?:0){
1->holder.binding.image.setImageResource(R.mipmap.img_mapstyle_1)
2->holder.binding.image.setImageResource(R.mipmap.img_mapstyle_2)
3->holder.binding.image.setImageResource(R.mipmap.img_mapstyle_3)
4->holder.binding.image.setImageResource(R.mipmap.img_mapstyle_4)
}
if(list?.get(position)?.isSelected == true){
position: Int
) {
ImageLoader.ImageBuilder.with(context)
.setTargetView(holder.binding.image)
.setUrl(list?.get(position)?.img).start()
holder.binding.tvName.text = list?.get(position)?.name
if (list?.get(position)?.isSelected == true) {
holder.binding.ivSelected.visibility = View.VISIBLE
}else{
} else {
holder.binding.ivSelected.visibility = View.GONE
}
RxUtils.onMultiClick(holder.binding.image){
if(list?.get(position)?.isSelected==true)return@onMultiClick
RxUtils.onMultiClick(holder.binding.image) {
if (list?.get(position)?.isSelected == true) return@onMultiClick
if (list?.get(position)?.type == "1" && !UserManager.INSTANCE.getVipFlag()) {
AppManager.getAppManager().currentActivity?.apply {
this.startActivity(
Intent(
this, OpenvipActivity::class.java
)
)
}
return@onMultiClick
}
list?.forEach {
it.isSelected = false
}
list?.get(position)?.isSelected =true
onItemMapStyleChange?.onItemChange(list?.get(position)?.img?:0)
list?.get(position)?.isSelected = true
onItemMapStyleChange?.onItemChange(list?.get(position)?.key ?: "hybrid")
notifyDataSetChanged()
}
}
override fun getItemCount() = list?.size?:0
override fun getItemCount() = list?.size ?: 0
override fun onCreateLayoutHelper(): LayoutHelper {
val helper = GridLayoutHelper(2)
......@@ -57,7 +70,7 @@ class DialogMapContentAdapter(val context: Context, var list: List<MapStyleList>
override fun getLayoutId(viewType: Int) = R.layout.dialog_map_content_item
interface OnItemMapStyleChange{
fun onItemChange(type:Int)
interface OnItemMapStyleChange {
fun onItemChange(type: String)
}
}
\ No newline at end of file
......@@ -5,6 +5,7 @@ import com.mints.street.netwrok.common.HttpManager
import io.reactivex.Observable
import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.POST
/**
......@@ -145,4 +146,9 @@ interface MainApi {
@POST("na/getAttractionsList")
fun getHotView(@Body vo:@JvmSuppressWildcards Map<String,Any>):Observable<Response<BaseResponse<HotViewBean>>>
/**
* 地图是否收费
*/
@POST("na/getMapChargeConfig")
fun getMapChargeConfig():Observable<Response<BaseResponse<MapStyleSort>>>
}
\ No newline at end of file
package com.mints.street.bean
/**
* Created by 冯瑞雨 on 2021/8/16.
*/
class InitMapBean {
var lat: Double = 0.0
var lng: Double = 0.0
var vip: Int? = 0//0 非vip 1 vip
var inner: Int? = 0// 0国内 ,1国外
}
\ No newline at end of file
......@@ -10,11 +10,12 @@ class MapStyleSortBean {
}
class MapStyleSort{
var name:String?=null
var mapStyleList:List<MapStyleList>?=null
var list:List<MapStyleList>?=null
}
class MapStyleList{
var name:String?=null
var img:Int=0
var key:String?=null
var type:String?=null//是否收费
var img:String?=null
var isSelected:Boolean?=false
}
......@@ -4,7 +4,6 @@ import android.Manifest
import android.os.Build
import android.os.Bundle
import android.view.KeyEvent
import android.view.MotionEvent
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
......@@ -17,7 +16,6 @@ import com.mints.street.BR
import com.mints.street.R
import com.mints.street.databinding.ActivityMainBinding
import com.mints.street.main.googlemap.GoogleMapFragment
import com.mints.street.main.home.HomeFragment
import com.mints.street.main.my.MyFragment
import com.mints.street.main.vr.VRFragment
import com.mints.street.manager.UserManager
......@@ -25,6 +23,7 @@ import com.mints.street.manager.oaid.OaidManager
import com.permissionx.guolindev.PermissionX
import com.permissionx.guolindev.callback.RequestCallback
import me.goldze.mvvmhabit.base.AppManager
import me.goldze.mvvmhabit.utils.KLog
import me.goldze.mvvmhabit.utils.ToastUtils
......@@ -37,29 +36,20 @@ class MainActivity : BaseActivity<ActivityMainBinding, MainViewModel>() {
override fun getStatusBarHeightView(): View? {
return null
}
private val homeFragment = HomeFragment()
override fun initData() {
super.initData()
OaidManager.init()
//初始化viewpager2
binding.mainViewpager.initMain(this,homeFragment)
binding.mainViewpager.initMain(this)
//初始化 bottomBarF
binding.mainBottom.init {
when (it) {
R.id.menu_home -> {
if (UserManager.INSTANCE.userIsLogin() && UserManager.INSTANCE.getVipFlag()) {
binding.mainViewpager.setCurrentItem(3, false)
} else {
binding.mainViewpager.setCurrentItem(0, false)
}
}
R.id.menu_home -> binding.mainViewpager.setCurrentItem(0, false)
R.id.menu_square -> binding.mainViewpager.setCurrentItem(1, false)
R.id.menu_my -> {
binding.mainViewpager.setCurrentItem(2, false)
// stopAnim()
}
R.id.menu_my -> { binding.mainViewpager.setCurrentItem(2, false) }
}
}
//加载本地GIF动图
......@@ -81,15 +71,7 @@ class MainActivity : BaseActivity<ActivityMainBinding, MainViewModel>() {
viewModel.checkUpgrade()
}
override fun onResume() {
super.onResume()
if (binding.mainViewpager.currentItem == 0){
if (UserManager.INSTANCE.userIsLogin() && UserManager.INSTANCE.getVipFlag()) {
binding.mainViewpager.setCurrentItem(3, false)
}
}
}
var oldTime: Long = 0
override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
when (keyCode) {
......@@ -108,19 +90,18 @@ class MainActivity : BaseActivity<ActivityMainBinding, MainViewModel>() {
}
override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
if (ev.action == MotionEvent.ACTION_MOVE){
//触点的个数,就是有几个手指同时接触屏幕
if (ev.pointerCount==1){
homeFragment.updateGesture(true)
}else{
homeFragment.updateGesture(false)
}
}
return super.dispatchTouchEvent(ev)
}
// override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
// if (ev.action == MotionEvent.ACTION_MOVE) {
// //触点的个数,就是有几个手指同时接触屏幕
// if (ev.pointerCount == 1) {
// homeFragment.updateGesture(true)
// } else {
// homeFragment.updateGesture(false)
// }
// }
//
// return super.dispatchTouchEvent(ev)
// }
}
......@@ -137,11 +118,11 @@ private fun BottomNavigationViewEx.init(navigationItemSelectedAction: (Int) -> U
return this
}
private fun ViewPager2.initMain(activity: MainActivity,homeFragment:HomeFragment): ViewPager2 {
private fun ViewPager2.initMain(activity: MainActivity): ViewPager2 {
//是否可滑动
this.isUserInputEnabled = false
//预加载
this.offscreenPageLimit = 4
// this.offscreenPageLimit = 2
//设置适配器
adapter = object : FragmentStateAdapter(activity) {
......@@ -149,7 +130,7 @@ private fun ViewPager2.initMain(activity: MainActivity,homeFragment:HomeFragment
return when (position) {
0 -> {
//首页
homeFragment
GoogleMapFragment()
}
1 -> {
//广场
......@@ -159,16 +140,13 @@ private fun ViewPager2.initMain(activity: MainActivity,homeFragment:HomeFragment
//个人中心
MyFragment()
}
3 -> {
GoogleMapFragment()
}
else -> {
//首页
HomeFragment()
GoogleMapFragment()
}
}
}
override fun getItemCount() = 4
......
......@@ -3,8 +3,11 @@ package com.mints.street.main.googlemap
import android.os.Bundle
import android.os.Handler
import android.view.LayoutInflater
import android.view.MotionEvent
import android.view.View
import android.view.ViewGroup
import android.webkit.WebChromeClient
import android.widget.EditText
import androidx.lifecycle.Observer
import com.baidu.location.BDLocation
import com.baidu.location.BDLocationListener
......@@ -17,16 +20,16 @@ import com.google.gson.Gson
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.bean.ViewRecommedBean
import com.mints.street.bean.*
import com.mints.street.databinding.ActivityGoogleMapBinding
import com.mints.street.main.home.HomeViewModel
import com.mints.street.main.home.SearchMapActivity
import com.mints.street.main.my.OpenvipActivity
import com.mints.street.manager.UserManager
import com.mints.street.webview.MintsWebViewActivity
import com.mints.street.widget.ScrollLayout
import com.mints.street.widget.dialog.DialogMapStyle
import com.mints.street.widget.dialog.DialogUtils.showupgradevipDialog
import com.mints.street.widget.dialog.HotViewDialog
import com.mints.street.widget.dialog.ViewRecommedDialog
import me.goldze.mvvmhabit.base.AppManager
......@@ -44,19 +47,21 @@ class GoogleMapFragment() : BaseFragment<ActivityGoogleMapBinding, HomeViewModel
var mLocationClient: LocationClient? = null
private val myListener: MyLocationListener = MyLocationListener()
private var isScrollLayoutClose: Boolean = false
//弹出框
//地图样式弹出框
private var dialogMapStyle: DialogMapStyle? = null
private var gps = GPS(39.915121, 116.403947,0)
private var gps = GPS(39.915121, 116.403947, 0)
inner class MyLocationListener : BDLocationListener {
override fun onReceiveLocation(location: BDLocation?) {//4.9E-324 4.9E-324
if( location?.latitude == 4.9E-324 ||location?.longitude == 4.9E-324){
if (location?.latitude == 4.9E-324 || location?.longitude == 4.9E-324) {
return
}
gps.lat = location?.latitude?:39.915121
gps.lng = location?.longitude?:116.403947
KLog.e("onReceiveLocation","${location?.latitude} --- ${location?.longitude}")
gps.lat = location?.latitude ?: 39.915121
gps.lng = location?.longitude ?: 116.403947
KLog.e("onReceiveLocation", "${location?.latitude} --- ${location?.longitude}")
}
}
......@@ -70,9 +75,8 @@ class GoogleMapFragment() : BaseFragment<ActivityGoogleMapBinding, HomeViewModel
override fun onResume() {
viewModel.authorized()
super.onResume()
isLoginAndVipTrue()
}
override fun initData() {
......@@ -83,6 +87,7 @@ class GoogleMapFragment() : BaseFragment<ActivityGoogleMapBinding, HomeViewModel
binding.webview.webChromeClient = WebChromeClient()
binding.webview.setOnLongClickListener { true }
binding.webview.setDefaultHandler(object : DefaultHandler() {
override fun handler(data: String, function: CallBackFunction) {
CommonDialogUtils.showMessage(AppManager.getAppManager().currentActivity,
......@@ -92,6 +97,51 @@ class GoogleMapFragment() : BaseFragment<ActivityGoogleMapBinding, HomeViewModel
})
}
})
viewModel.getMapBean()
//定位
initPosition()
// js -> android
jsToAndroid()
binding.imageLocationIcon.setOnClickListener {
initZsMap()
}
RxUtils.onMultiClick(binding.stbBgSearch) {
SearchMapActivity.startSearchMapActivity(this)
}
//点击地图样式
RxUtils.onMultiClick(binding.imageMapChangeIcon) {
if (dialogMapStyle == null){
viewModel.getMapStyle()
}else{
if (this@GoogleMapFragment.fragmentManager != null) {
dialogMapStyle?.show(this@GoogleMapFragment.fragmentManager!!, "dialogMapStyle")
}
}
} //点击热门景点
RxUtils.onMultiClick(binding.lyHotview) {
HotViewDialog(requireActivity(), viewModel,
gps.lat, gps.lng,
this@GoogleMapFragment, object : HotViewDialog.OnHotItemClick {
override fun onItemClick(position: Int, itemBean: HotViewBean.Dataslist?) {
itemBean?.apply {
//todo 冯瑞雨 修改toDouble
//点击调转页面
viewModel.authorized(bvid, name)
//更新当前坐标(控制js页面做回调)
initZsMap(lat?.toDouble(), lng?.toDouble())
}
}
}).init().show()
}
}
/**
* 调用 JS - >android
*/
private fun jsToAndroid() {
//提供给js使用
binding.webview.registerHandler("tips") { data, _ ->
ToastUtils.showLong(data)
......@@ -154,103 +204,63 @@ class GoogleMapFragment() : BaseFragment<ActivityGoogleMapBinding, HomeViewModel
} catch (e: Exception) {
KLog.e("实体类转换错误")
}
ViewRecommedDialog(context,bean,gps,viewModel).init().show()
ViewRecommedDialog(context, bean, gps, viewModel).init().show()
}
//android->js调起付费页面
binding.webview.registerHandler("needPay") { _, _ ->
startActivity(OpenvipActivity::class.java)
}
//android->js调起升级的弹出框
binding.webview.registerHandler("needPayPopup") { _, _ ->
showupgradevipDialog(this.context)
}
viewModel.getMapBean()
//定位
initPosition()
//使地图缩放级别增大一级
binding.imageIn.setOnClickListener {
binding.webview.callHandler("addZoom"
,null ) {
binding.webview.callHandler(
"addZoom", null
) {
}
}
//使地图缩放级别减小一级
binding.imageOut.setOnClickListener {
binding.webview.callHandler("reduceZoom"
,null ) {
}
}
binding.imageLocationIcon.setOnClickListener {
initZsMap()
}
RxUtils.onMultiClick(binding.stbBgSearch) {
SearchMapActivity.startSearchMapActivity(this)
}
//点击地图样式
RxUtils.onMultiClick(binding.imageMapChangeIcon) {
context?.apply {
if (dialogMapStyle == null) {
dialogMapStyle = DialogMapStyle(this,viewModel.mapStyleSortBean.value,
object :DialogMapStyle.OnMapStyleDataChange{
override fun onMapStyleItemChange(type: Int) {
changeMapType(type)
}
override fun onRecommendedPlacesChange(isSelected: Boolean) {
if (isSelected){
if(viewModel.viewRecommed.value==null){
viewModel.getviewrecommend()
}else{
openScenics(viewModel.viewRecommed.value)
}
}else{
closeScenics()
}
}
override fun onStreetViewMapChange(isSelected: Boolean) {
changeVrButton(isSelected)
}
})
}
if (this@GoogleMapFragment.fragmentManager != null) {
dialogMapStyle?.show(this@GoogleMapFragment.fragmentManager!!, "dialogMapStyle")
binding.webview.callHandler(
"reduceZoom", null
) {
}
}
} //点击热门景点
RxUtils.onMultiClick(binding.lyHotview) {
HotViewDialog(requireActivity(), viewModel,
gps.lat, gps.lng,
this@GoogleMapFragment,object :HotViewDialog.OnHotItemClick{
override fun onItemClick(position: Int, itemBean: HotViewBean.Dataslist?) {
itemBean?.apply {
//todo 冯瑞雨 修改toDouble
//点击调转页面
viewModel.authorized(bvid,name)
//更新当前坐标(控制js页面做回调)
binding.webview.callHandler("initZsMap"
,Gson().toJson(GPS(lat?.toDouble()?:0.0,
lng?.toDouble()?:0.0,0)) ) {
}
}
}
}).init().show()
}
}
/**
* 调用JS
*/
private fun initZsMap() {
binding.webview.callHandler("initZsMap"
,Gson().toJson(gps) ) {
private fun initZsMap(lat: Double? = null, lng: Double? = null, inner: Int = 0) {
val initMapBean = InitMapBean()
initMapBean.lat = lat ?: gps.lat
initMapBean.lng = lng ?: gps.lng
if (viewModel.isLoginAndVipEqualTrue == true) {
//vip
initMapBean.vip = 1
} else {
//非vip
initMapBean.vip = 0
}
initMapBean.inner = inner
binding.webview.callHandler(
"initZsMap", Gson().toJson(initMapBean)
) {
}
}
/**
* 开关街景按钮
*/
private fun changeVrButton(isShow:Boolean){
var mutualBean=MutualBean()
mutualBean.show= if (isShow)1 else 0
binding.webview.callHandler("changeVrButton"
,Gson().toJson(mutualBean) ) {
private fun changeVrButton(isShow: Boolean) {
var mutualBean = MutualBean()
mutualBean.show = if (isShow) 1 else 0
binding.webview.callHandler(
"changeVrButton", Gson().toJson(mutualBean)
) {
}
}
......@@ -258,35 +268,48 @@ class GoogleMapFragment() : BaseFragment<ActivityGoogleMapBinding, HomeViewModel
* 调用JS方法
* 开启景点
*/
private fun openScenics(bean :HotViewBean?){
binding.webview.callHandler("showScenics"
,Gson().toJson(bean) ) {
private fun openScenics(bean: HotViewBean?) {
binding.webview.callHandler(
"showScenics", Gson().toJson(bean)
) {
}
}
/**
* 调用JS方法
* 关闭景点
*/
private fun closeScenics(){
binding.webview.callHandler("closeScenics"
,null ) {
private fun closeScenics() {
binding.webview.callHandler(
"closeScenics", null
) {
}
}
/**
* 调用JS方法
* 切换图层
*/
private fun changeMapType(type:Int=0){
var mutualBean=MutualBean()
when(type){
1->mutualBean.type="hybrid"
2->mutualBean.type="satellite"
3->mutualBean.type="terrain"
4->mutualBean.type="roadmap"
private fun changeMapType(type: String) {
var mutualBean = MutualBean()
mutualBean.type = type
binding.webview.callHandler(
"changeMapType", Gson().toJson(mutualBean)
) {
}
binding.webview.callHandler("changeMapType"
,Gson().toJson(mutualBean) ) {
}
/**
* 检测是否登录
*/
private fun isLoginAndVipTrue() {
if (viewModel.isLoginAndVipEqualTrue != UserManager.INSTANCE.getVipFlag() ||
viewModel.isLoginAndVipEqualTrue == null
) {
viewModel.isLoginAndVipEqualTrue = UserManager.INSTANCE.getVipFlag()
viewModel.authorized()
}
}
private fun initPosition() {
......@@ -340,23 +363,43 @@ 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
// }&gk=${gk}&bk=${bk}&base=${base}&ut=${ut}")
binding.webview.loadUrl(
"file:///android_asset/web/zsmap.html?u=${
u
}&gk=${gk}&bk=${bk}&base=${base}&ut=${ut}"
)
}
})
viewModel.pt.observe(this, Observer {
KLog.a("GPSConverterUtils.bd09_To_Gcj02", Gson().toJson(it))
binding.webview.callHandler("initZsMap"
,Gson().toJson(it) ) {
}
initZsMap(it.lat, it.lng)
binding.scrollLayout.toggle(ScrollLayout.STATUS_CLOSE)
})
viewModel.mapStyleSortBean.observe(this, Observer {
it?.apply {
dialogMapStyle?.apply {
this.mapStyleBean = it
dialogMapStyle = DialogMapStyle(context!!, it,
object : DialogMapStyle.OnMapStyleDataChange {
override fun onMapStyleItemChange(type: String) {
changeMapType(type)
}
override fun onRecommendedPlacesChange(isSelected: Boolean) {
if (isSelected) {
if (viewModel.viewRecommed.value == null) {
viewModel.getviewrecommend()
} else {
openScenics(viewModel.viewRecommed.value)
}
} else {
closeScenics()
}
}
override fun onStreetViewMapChange(isSelected: Boolean) {
changeVrButton(isSelected)
}
})
if (this@GoogleMapFragment.fragmentManager != null) {
dialogMapStyle?.show(this@GoogleMapFragment.fragmentManager!!, "dialogMapStyle")
}
}
......@@ -367,6 +410,7 @@ class GoogleMapFragment() : BaseFragment<ActivityGoogleMapBinding, HomeViewModel
}
})
}
override fun onDestroy() {
super.onDestroy()
......@@ -378,6 +422,5 @@ class GoogleMapFragment() : BaseFragment<ActivityGoogleMapBinding, HomeViewModel
it.destroy()
}
}
}
......@@ -130,7 +130,9 @@ class HomeFragment() : BaseFragment<FragmentHomeBinding, HomeViewModel>(), Senso
}
//地图样式
RxUtils.onMultiClick(binding.imageMapChangeIcon) {
if (!com.mints.street.manager.UserManager.INSTANCE.userIsLogin()&&!com.mints.street.manager.UserManager.INSTANCE.getVipFlag()){
if (!com.mints.street.manager.UserManager.
INSTANCE.userIsLogin()&&!com.mints.street.
manager.UserManager.INSTANCE.getVipFlag()){
startActivity(OpenvipActivity::class.java)
}
......
......@@ -16,11 +16,13 @@ import com.mints.street.model.ApiModel
import com.mints.street.netwrok.base.HttpSubscribeImpl
import com.mints.street.utils.DeviceUuidFactory
import com.mints.street.webview.MintsWebViewActivity
import io.reactivex.Observable
import me.goldze.mvvmhabit.base.AppManager
import me.goldze.mvvmhabit.base.BaseViewModel
import me.goldze.mvvmhabit.utils.KLog
import me.goldze.mvvmhabit.utils.SPUtils
import me.tatarka.bindingcollectionadapter2.ItemBinding
import retrofit2.Response
import java.io.BufferedReader
import java.io.InputStreamReader
......@@ -33,14 +35,22 @@ class HomeViewModel(application: Application) : BaseViewModel(application) {
var addressList = ObservableArrayList<HomeButtonItemVM?>()
var addressItemBinding =
ItemBinding.of<HomeButtonItemVM>(BR.viewModel, R.layout.item_home_button)
var isLoginAndVipEqualTrue:Boolean?=null
//搜索页面回调 谷歌GPS
var pt = MutableLiveData<GPS>()
val authorizedBean = MutableLiveData<AuthorizedBean>()
fun authorized() {
ApiModel.authorized().safeSubscribe(object
var authorized : Observable< Response<BaseResponse<AuthorizedBean>>>?=null
if (isLoginAndVipEqualTrue == true){
//vip
authorized = ApiModel.authorized()
}else{
//非vip
authorized = ApiModel.authorizedA()
}
authorized.safeSubscribe(object
: HttpSubscribeImpl<BaseResponse<AuthorizedBean>>(
null, false
) {
......@@ -50,7 +60,6 @@ class HomeViewModel(application: Application) : BaseViewModel(application) {
}
authorizedBean.value = response.result
}
})
}
......@@ -241,26 +250,21 @@ class HomeViewModel(application: Application) : BaseViewModel(application) {
/**
* 获取地图展示样式
*/
val mapStyleSortBean = MutableLiveData<MapStyleSortBean>(getMapStyle())
fun getMapStyle():MapStyleSortBean?{
val assets = AppManager.getAppManager().currentActivity.assets
val stringBuilder = StringBuilder()
var mapBean: MapStyleSortBean? = null
try {
//通过管理器打开文件并读取
val bf = BufferedReader(
InputStreamReader(
assets.open("mapStyle.json")
)
)
var line: String?
while (bf.readLine().also { line = it } != null) {
stringBuilder.append(line)
val mapStyleSortBean = MutableLiveData<MapStyleSortBean>()
fun getMapStyle(){
ApiModel.getMapChargeConfig(lifecycleProvider).safeSubscribe(object
:HttpSubscribeImpl<BaseResponse<MapStyleSort>>(this@HomeViewModel){
override fun onBusinessSuccess(response: BaseResponse<MapStyleSort>) {
response.result.name = "常用"
val bean = MapStyleSortBean()
bean.isStreetViewMap = true
bean.isRecommendedPlaces = false
if (response.result.list!=null && response.result.list?.size?:0>0){
response.result.list?.get(0)?.isSelected = true
}
bean.mapStyleSort = listOf(response.result)
mapStyleSortBean.value = bean
}
mapBean = Gson().fromJson(stringBuilder.toString(), MapStyleSortBean::class.java)
} catch (e: Exception) {
KLog.e("读取assets文件下的json出问题")
}
return mapBean
})
}
}
\ No newline at end of file
......@@ -149,8 +149,18 @@ object ApiModel {
/**
* 请求热门景点数据
*/
fun getHotView(lifecycleProvider: LifecycleProvider<Any>?, map: HashMap<String, Any>):Observable<Response<BaseResponse<HotViewBean>>>{
return HttpManager.getInstance().execute(lifecycleProvider,MainApi.newInstance().getHotView(map))
fun getHotView(lifecycleProvider: LifecycleProvider<Any>?,
map: HashMap<String, Any>):Observable<Response<BaseResponse<HotViewBean>>>{
return HttpManager.getInstance().execute(lifecycleProvider,
MainApi.newInstance().getHotView(map))
}
/**
* 地图是否收费
*/
fun getMapChargeConfig(lifecycleProvider: LifecycleProvider<Any>?)
:Observable<Response<BaseResponse<MapStyleSort>>>{
return HttpManager.getInstance().execute(lifecycleProvider,
MainApi.newInstance().getMapChargeConfig())
}
}
\ No newline at end of file
package com.mints.street.widget.dialog
import androidx.fragment.app.FragmentActivity
import com.mints.street.login.OnLoginListener
class BenfitDialog(context: FragmentActivity){
}
\ No newline at end of file
......@@ -66,9 +66,9 @@ class DialogMapStyle(
mapStyleBean?.mapStyleSort?.forEach {
mAdapter?.addAdapter(DialogMapHeadAdapter(mContext, it.name))
mAdapter?.addAdapter(
DialogMapContentAdapter(mContext, it.mapStyleList,
DialogMapContentAdapter(mContext, it.list,
object : DialogMapContentAdapter.OnItemMapStyleChange {
override fun onItemChange(type: Int) {
override fun onItemChange(type: String) {
onMapStyleDataChange?.onMapStyleItemChange(type)
}
})
......@@ -92,7 +92,7 @@ class DialogMapStyle(
)
}
interface OnMapStyleDataChange{
fun onMapStyleItemChange(type:Int)
fun onMapStyleItemChange(type:String)
fun onRecommendedPlacesChange(isSelected: Boolean)
fun onStreetViewMapChange(isSelected: Boolean)
}
......
......@@ -22,7 +22,7 @@ object DialogUtils {
dialogListener.setDialog(bonusDialog)
}
fun showupgradevipDialog(ctx: Context){
fun showupgradevipDialog(ctx: Context?){
val weakReference = WeakReference<Context>(ctx)
val bonusDialog = UpgradeVipDialog(weakReference.get()!!)
bonusDialog.show()
......
......@@ -30,6 +30,7 @@
android:src="@mipmap/map_select_icon"
/>
<TextView
android:id="@+id/tv_name"
android:paddingTop="10dp"
app:layout_constraintTop_toBottomOf="@+id/image"
app:layout_constraintStart_toStartOf="parent"
......
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