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