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

添加新人福利弹出逻辑

parent 6c1c6389
......@@ -41,6 +41,10 @@ import me.goldze.mvvmhabit.utils.SPUtils
*/
class HomeFragment : BaseFragment<FragmentHomeBinding, HomeViewModel>(), SensorEventListener {
companion object {
val IS_FIRST_OPEN: String = "isFirstOpen"
}
private var mBaiduMap: BaiduMap? = null
// 定位相关
......@@ -122,7 +126,7 @@ class HomeFragment : BaseFragment<FragmentHomeBinding, HomeViewModel>(), SensorE
})
viewModel.mapbeanData.observe(this, Observer<MapBean> {
DialogUtils.showbennfitsDialog(context!!,viewModel,it.innerPlaces?.places)
DialogUtils.showbennfitsDialog(context!!, viewModel, it.innerPlaces?.places)
})
}
......
......@@ -20,6 +20,7 @@ import com.mints.street.webview.MintsWebViewActivity
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 java.io.BufferedReader
import java.io.InputStreamReader
......@@ -77,11 +78,11 @@ class HomeViewModel(application: Application) : BaseViewModel(application) {
}
var mapbeanData=MutableLiveData<MapBean>()
var mapbeanData = MutableLiveData<MapBean>()
fun getMapBean() {
val assets = AppManager.getAppManager().currentActivity.assets
val stringBuilder = StringBuilder()
var mapBean:MapBean?=null
var mapBean: MapBean? = null
try {
//通过管理器打开文件并读取
val bf = BufferedReader(
......@@ -92,7 +93,11 @@ class HomeViewModel(application: Application) : BaseViewModel(application) {
while (bf.readLine().also { line = it } != null) {
stringBuilder.append(line)
}
mapbeanData.value= Gson().fromJson(stringBuilder.toString(), MapBean::class.java)
if ( SPUtils.getInstance().decodeBoolean(HomeFragment.IS_FIRST_OPEN,true)){
mapbeanData.value = Gson().fromJson(stringBuilder.toString(), MapBean::class.java)
SPUtils.getInstance().encode(HomeFragment.IS_FIRST_OPEN,false)
}
mapBean = Gson().fromJson(stringBuilder.toString(), MapBean::class.java)
} catch (e: Exception) {
......@@ -148,30 +153,4 @@ class HomeViewModel(application: Application) : BaseViewModel(application) {
}
}
}
//获取vr街景数据
val VrmapBean: MutableLiveData<VrmapBean> = MutableLiveData()
fun vrPlaces() {//无参数传递
ApiModel.vrPlaces(lifecycleProvider).safeSubscribe(
object : HttpSubscribeImpl<BaseResponse<VrmapBean>>(
this@HomeViewModel, true) {
override fun onBusinessSuccess(response: BaseResponse<VrmapBean>) {
VrmapBean.value = response.result
val a: MutableList<ScenicSpotBean> = ArrayList()
for (item in response.result.internal!!) {
a.add(ScenicSpotBean(name = item.name, url = item.url
, starRating = item.stars, images = item.img))
}
// AppDatabase.instance().scenicSpotDao().addVRFreeZoneAll(a)
// for(item in AppDatabase.instance().scenicSpotDao().getVRFreeZoneAll()){
// KLog.e("AppDatabase.instance().scenicSpotDao().getVRFreeZoneAll()",item.toString())
// }
}
override fun onError(e: Throwable) {
KLog.e("vrPlaces", "请求失败 : $e")
}
}
)
}
}
\ No newline at end of file
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