Commit 4fb3c46b authored by fengruiyu's avatar fengruiyu

Merge branch 'branche_zsf' of http://39.97.65.143:81/android/android_street into fry_dev

 Conflicts:
	app/src/main/java/com/mints/street/main/home/HomeViewModel.kt
解决冲突
parents f3c1651d a36b1330
package com.mints.street.main.home
import android.app.Dialog
import android.content.Context.SENSOR_SERVICE
import android.hardware.Sensor
import android.hardware.SensorEvent
......@@ -9,7 +8,6 @@ import android.hardware.SensorManager
import android.os.Bundle
import android.os.Handler
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.lifecycle.Observer
import com.baidu.location.BDLocation
......@@ -28,7 +26,6 @@ import com.mints.street.databinding.FragmentHomeBinding
import com.mints.street.manager.UmengManager
import com.mints.street.utils.GPSConverterUtils
import com.mints.street.widget.ScrollLayout
import com.mints.street.widget.dialog.DialogListener
import com.mints.street.widget.dialog.DialogUtils
import me.goldze.mvvmhabit.base.AppManager
import me.goldze.mvvmhabit.utils.KLog
......@@ -41,6 +38,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
// 定位相关
......@@ -79,9 +80,9 @@ class HomeFragment : BaseFragment<FragmentHomeBinding, HomeViewModel>(), SensorE
override fun initContentView(
inflater: LayoutInflater?,
container: ViewGroup?,
savedInstanceState: Bundle?
inflater: LayoutInflater?,
container: ViewGroup?,
savedInstanceState: Bundle?
) = R.layout.fragment_home
override fun initVariableId() = BR.viewModel
......@@ -122,7 +123,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)
})
}
......@@ -202,13 +203,13 @@ class HomeFragment : BaseFragment<FragmentHomeBinding, HomeViewModel>(), SensorE
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
)
// 开启定位图层
......@@ -286,11 +287,11 @@ class HomeFragment : BaseFragment<FragmentHomeBinding, HomeViewModel>(), SensorE
mCurrentLon = location.longitude
mCurrentAccracy = location.radius
myLocationData = MyLocationData.Builder()
.accuracy(location.radius) // 设置定位数据的精度信息,单位:米
.direction(mCurrentDirection.toFloat()) // 此处设置开发者获取到的方向信息,顺时针0-360
.latitude(location.latitude)
.longitude(location.longitude)
.build()
.accuracy(location.radius) // 设置定位数据的精度信息,单位:米
.direction(mCurrentDirection.toFloat()) // 此处设置开发者获取到的方向信息,顺时针0-360
.latitude(location.latitude)
.longitude(location.longitude)
.build()
this.setMyLocationData(myLocationData)
if (isFirstLoc) {
isFirstLoc = false
......@@ -306,15 +307,15 @@ class HomeFragment : BaseFragment<FragmentHomeBinding, HomeViewModel>(), SensorE
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
......
......@@ -9,7 +9,6 @@ import com.mints.street.BR
import com.mints.street.R
import com.mints.street.bean.*
import com.mints.street.common.DeviceInfo
import com.mints.street.db.ScenicSpotBean
import com.mints.street.main.my.OpenvipActivity
import com.mints.street.manager.UserManager
import com.mints.street.manager.oaid.OaidManager
......@@ -31,7 +30,8 @@ class HomeViewModel(application: Application) : BaseViewModel(application) {
var addressList = ObservableArrayList<HomeButtonItemVM?>()
var addressItemBinding = ItemBinding.of<HomeButtonItemVM>(BR.viewModel, R.layout.item_home_button)
var addressItemBinding =
ItemBinding.of<HomeButtonItemVM>(BR.viewModel, R.layout.item_home_button)
var pt = MutableLiveData<GPS>()
val authorizedBean = MutableLiveData<AuthorizedBean>()
......@@ -40,10 +40,10 @@ class HomeViewModel(application: Application) : BaseViewModel(application) {
fun authorized() {
ApiModel.authorized().safeSubscribe(object
: HttpSubscribeImpl<BaseResponse<AuthorizedBean>>(
null,false
null, false
) {
override fun onBusinessSuccess(response: BaseResponse<AuthorizedBean>) {
if(Gson().toJson(response.result).equals(Gson().toJson(authorizedBean.value))){
if (Gson().toJson(response.result).equals(Gson().toJson(authorizedBean.value))) {
return
}
authorizedBean.value = response.result
......@@ -51,117 +51,137 @@ class HomeViewModel(application: Application) : BaseViewModel(application) {
})
}
fun authorized(name:String?=null,lat:String?,lng:String?,isLook:Boolean) {
if (isLook){
fun authorized(name: String? = null, lat: String?, lng: String?, isLook: Boolean) {
if (isLook) {
ApiModel.authorizedA().safeSubscribe(object
: HttpSubscribeImpl<BaseResponse<AuthorizedBean>>(
this@HomeViewModel,false
this@HomeViewModel, false
) {
override fun onBusinessSuccess(response: BaseResponse<AuthorizedBean>) {
if(!Gson().toJson(response.result).equals(Gson().toJson(authorizedBean.value))){
if (!Gson().toJson(response.result)
.equals(Gson().toJson(authorizedBean.value))
) {
authorizedBean.value = response.result
}
MintsWebViewActivity.startWebView(name,
MintsWebViewActivity.toBaduVR(lat,lng,response.result?.bk))
MintsWebViewActivity.startWebView(
name,
MintsWebViewActivity.toBaduVR(lat, lng, response.result?.bk)
)
}
})
}else{
if((!UserManager.INSTANCE.userIsLogin() && !UserManager.INSTANCE.getVipFlag())){
} else {
if ((!UserManager.INSTANCE.userIsLogin() && !UserManager.INSTANCE.getVipFlag())) {
startActivity(OpenvipActivity::class.java)
return
}
ApiModel.authorized().safeSubscribe(object
: HttpSubscribeImpl<BaseResponse<AuthorizedBean>>(
this@HomeViewModel,false
this@HomeViewModel, false
) {
override fun onBusinessSuccess(response: BaseResponse<AuthorizedBean>) {
if(!Gson().toJson(response.result).equals(Gson().toJson(authorizedBean.value))){
if (!Gson().toJson(response.result)
.equals(Gson().toJson(authorizedBean.value))
) {
authorizedBean.value = response.result
}
MintsWebViewActivity.startWebView(name,
MintsWebViewActivity.toBaduVR(lat,lng,response.result?.bk))
MintsWebViewActivity.startWebView(
name,
MintsWebViewActivity.toBaduVR(lat, lng, response.result?.bk)
)
}
})
}
}
var mapbeanData=MutableLiveData<MapBean>()
fun getMapBean() {
val assets = AppManager.getAppManager().currentActivity.assets
val stringBuilder = StringBuilder()
var mapBean:MapBean?=null
try {
//通过管理器打开文件并读取
val bf = BufferedReader(
InputStreamReader(
assets.open("map.json"))
)
var line: String?
while (bf.readLine().also { line = it } != null) {
stringBuilder.append(line)
}
mapbeanData.value= Gson().fromJson(stringBuilder.toString(), MapBean::class.java)
mapBean = Gson().fromJson(stringBuilder.toString(), MapBean::class.java)
var mapbeanData = MutableLiveData<MapBean>()
fun getMapBean() {
val assets = AppManager.getAppManager().currentActivity.assets
val stringBuilder = StringBuilder()
var mapBean: MapBean? = null
try {
//通过管理器打开文件并读取
val bf = BufferedReader(
InputStreamReader(
assets.open("map.json")
)
)
var line: String?
while (bf.readLine().also { line = it } != null) {
stringBuilder.append(line)
}
mapbeanData.value = Gson().fromJson(stringBuilder.toString(), MapBean::class.java)
mapBean = Gson().fromJson(stringBuilder.toString(), MapBean::class.java)
} catch (e: Exception) {
KLog.e("读取assets文件下的json出问题")
}
val bean = mapBean?.homePlaces?.places
bean?.iterator()?.forEach { item ->
if (item.images==null || item.images?.size!!<3){
return
} catch (e: Exception) {
KLog.e("读取assets文件下的json出问题")
}
addressList.add(HomeButtonItemVM(this, item.name
, item.images!![0],item.images!![1],item.images!![2]
,latitude = item.latitude.toString(),longitude = item.longitude.toString(),isLook = true
))
val bean = mapBean?.homePlaces?.places
bean?.iterator()?.forEach { item ->
if (item.images == null || item.images?.size!! < 3) {
return
}
addressList.add(
HomeButtonItemVM(
this,
item.name,
item.images!![0],
item.images!![1],
item.images!![2],
latitude = item.latitude.toString(),
longitude = item.longitude.toString(),
isLook = true
)
)
}
}
}
/**
* 打开激活
*/
fun comSaveTerminalInfo() {
val vo = HashMap<String, Any>()
val deviceInfo = DeviceInfo.instance
val macAddress: String = deviceInfo.getMacAddress()
val mac = macAddress.replace(":", "")
vo["mac"] = mac
vo["mac1"] = macAddress
vo["androidid"] = deviceInfo.getAndroidId(null)
vo["imei"] = deviceInfo.iMEI
vo["oaid"] = OaidManager.getOaid()
vo["os"] = "android"
vo["model"] = deviceInfo.newModel
vo["uuid"] = DeviceUuidFactory().deviceUuid
vo["osversion"] = deviceInfo.oSVersion
vo["appversion"] = deviceInfo.versionName
ApiModel.comSaveTerminalInfo(lifecycleProvider, vo).safeSubscribe(
/**
* 打开激活
*/
fun comSaveTerminalInfo() {
val vo = HashMap<String, Any>()
val deviceInfo = DeviceInfo.instance
val macAddress: String = deviceInfo.getMacAddress()
val mac = macAddress.replace(":", "")
vo["mac"] = mac
vo["mac1"] = macAddress
vo["androidid"] = deviceInfo.getAndroidId(null)
vo["imei"] = deviceInfo.iMEI
vo["oaid"] = OaidManager.getOaid()
vo["os"] = "android"
vo["model"] = deviceInfo.newModel
vo["uuid"] = DeviceUuidFactory().deviceUuid
vo["osversion"] = deviceInfo.oSVersion
vo["appversion"] = deviceInfo.versionName
ApiModel.comSaveTerminalInfo(lifecycleProvider, vo).safeSubscribe(
object : HttpSubscribeImpl<BaseResponse<Any>>(
this@HomeViewModel, true) {
this@HomeViewModel, true
) {
override fun onBusinessSuccess(response: BaseResponse<Any>) {
}
override fun onError(e: Throwable) {
}
})
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (requestCode == 200 && resultCode == SearchMapActivity.REQUEST_CODE) {
data?.let {
pt.value = GPS(
it.getDoubleExtra("latitude", 0.0), it.getDoubleExtra("longitude", 0.0)
)
}
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (requestCode == 200 && resultCode == SearchMapActivity.REQUEST_CODE){
data?.let {
pt.value = GPS(it.getDoubleExtra("latitude",0.0),it.getDoubleExtra("longitude",0.0))
}
}
}
}
\ 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