Commit 641b378a authored by wanglei's avatar wanglei

...

parent 1052f0cc
...@@ -51,6 +51,7 @@ class MyApplication : Application() { ...@@ -51,6 +51,7 @@ class MyApplication : Application() {
AppPreferences.getInstance().put("uuid", uuid) AppPreferences.getInstance().put("uuid", uuid)
LogEx.logDebug(TAG, "uuid=$uuid") LogEx.logDebug(TAG, "uuid=$uuid")
} }
LogEx.logDebug(TAG, "uuid=${AppPreferences.getInstance().getString("uuid", "")}")
} }
fun initApp() { fun initApp() {
......
...@@ -37,7 +37,6 @@ object LocationPositionUtils { ...@@ -37,7 +37,6 @@ object LocationPositionUtils {
fun uploadMyLocation(latLng: LatLng, power: Int) { fun uploadMyLocation(latLng: LatLng, power: Int) {
Thread { Thread {
val pkg = ConfigHelper.packageName val pkg = ConfigHelper.packageName
val data = JSONObject() val data = JSONObject()
data.put("latitude", latLng.latitude) data.put("latitude", latLng.latitude)
data.put("longitude", latLng.longitude) data.put("longitude", latLng.longitude)
...@@ -54,15 +53,15 @@ object LocationPositionUtils { ...@@ -54,15 +53,15 @@ object LocationPositionUtils {
.put("${pkg}_14", BuildConfig.VERSION_CODE) .put("${pkg}_14", BuildConfig.VERSION_CODE)
.put("${pkg}_15", "google") .put("${pkg}_15", "google")
.put("${pkg}_24", BuildConfig.BUILD_TYPE) .put("${pkg}_24", BuildConfig.BUILD_TYPE)
LogEx.logDebug(TAG, "uuid=${AppPreferences.getInstance().getString("uuid", "")}")
val body = JSONObject() val body = JSONObject()
.put("data", data) .put("data", data)
.put("bp", bp) .put("bp", bp)
.toString() .toString()
val paramJson = AESHelper.encrypt(body) val paramJson = AESHelper.encrypt(body)
LogEx.logDebug(TAG, "uploadMyLocation paramJson=${paramJson}")
runCatching { runCatching {
LogEx.logDebug(TAG, "uploadUrl=${uploadUrl}") LogEx.logDebug(TAG, "uploadMyLocation uploadUrl=${uploadUrl}")
val result = ReportUtils.doPost(uploadUrl, HashMap(), paramJson) val result = ReportUtils.doPost(uploadUrl, HashMap(), paramJson)
LogEx.logDebug(TAG, "result=$result") LogEx.logDebug(TAG, "result=$result")
} }
...@@ -87,7 +86,7 @@ object LocationPositionUtils { ...@@ -87,7 +86,7 @@ object LocationPositionUtils {
*/ */
fun getLocation( fun getLocation(
device: String, device: String,
callBack: ((locationData: LocationData) -> Unit)? = null callBack: ((locationData: LocationData?) -> Unit)? = null
) { ) {
Thread { Thread {
val pkg = ConfigHelper.packageName val pkg = ConfigHelper.packageName
...@@ -121,7 +120,7 @@ object LocationPositionUtils { ...@@ -121,7 +120,7 @@ object LocationPositionUtils {
val decryptedData = AESHelper.decrypt(responseData) val decryptedData = AESHelper.decrypt(responseData)
LogEx.logDebug(TAG, "getLocation decryptedData=$decryptedData") LogEx.logDebug(TAG, "getLocation decryptedData=$decryptedData")
val locationData: LocationData? = parseLoginData(decryptedData) val locationData: LocationData? = parseLoginData(decryptedData)
locationData?.let { callBack?.invoke(it) } callBack?.invoke(locationData)
} }
} }
}.start() }.start()
......
...@@ -77,13 +77,16 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea ...@@ -77,13 +77,16 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea
private fun initAdapter() { private fun initAdapter() {
adapter = ViewingAdapter( adapter = ViewingAdapter(
itemClick = { itemClick = { viewingBean ->
if (currentViewingBean != it) { if (currentViewingBean != viewingBean) {
currentViewingBean = it removeOldViewingMarker()
startGetLocationJob() currentViewingBean = viewingBean
initFriendLocationMarker(it) setViewingBeanMarker()
} }
startGetLocationJob()
}, },
moreClick = { anchorView, item -> moreClick = { anchorView, item ->
showViewerMoreDialog(anchorView) showViewerMoreDialog(anchorView)
...@@ -101,18 +104,19 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea ...@@ -101,18 +104,19 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea
while (isActive) { while (isActive) {
currentViewingBean?.let { viewingBean -> currentViewingBean?.let { viewingBean ->
LogEx.logDebug(TAG, "startGetLocationJob")
LocationPositionUtils.getLocation(viewingBean.device) { locatDate -> LocationPositionUtils.getLocation(viewingBean.device) { locatDate ->
LogEx.logDebug(TAG, "locatDate=$locatDate") LogEx.logDebug(TAG, "getLocation ${viewingBean.device} locatDate=$locatDate")
currentViewingBean?.locatDate = locatDate
lifecycleScope.launch(Dispatchers.Main) { lifecycleScope.launch(Dispatchers.Main) {
if (BuildConfig.DEBUG) { if (BuildConfig.DEBUG) {
toast("${locatDate.latitude} ${locatDate.longitude}") toast("getLocation ${locatDate?.latitude} ${locatDate?.longitude}")
} }
val viewing = adapter.items.findLast { it.device == viewingBean.device } val viewing = adapter.items.findLast { it.device == viewingBean.device }
viewing?.locatDate = locatDate viewing?.locatDate = locatDate
adapter.notifyDataSetChanged() adapter.notifyDataSetChanged()
friendMarker?.position = LatLng(locatDate.latitude, locatDate.longitude)
setViewingBeanMarker()
} }
} }
} }
...@@ -262,22 +266,33 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea ...@@ -262,22 +266,33 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea
} }
} }
private fun initFriendLocationMarker(viewingBean: ViewingBean) { private fun setViewingBeanMarker() {
if (friendMarker != null) { currentViewingBean?.let { viewingBean ->
friendMarker?.remove() viewingBean.locatDate?.let { locatDate ->
friendMarker = null
} val latLng = LatLng(locatDate.latitude, locatDate.longitude)
val friendAvatar = LayoutInflater.from(this).inflate(R.layout.avatar_friend, null)
viewingBean.locatDate?.let { if (friendMarker == null) {
val latLng = LatLng(it.latitude, it.longitude) val friendAvatar = LayoutInflater.from(this).inflate(R.layout.avatar_friend, null)
friendMarker = map?.addLocationMarker(friendAvatar, latLng, viewingBean.nickname) LogEx.logDebug(TAG, "initViewingBeanMarker locatDate ${locatDate.latitude} ${locatDate.longitude}")
map?.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 15f)) friendMarker = map?.addLocationMarker(friendAvatar, latLng, viewingBean.nickname)
} }
if (viewingBean.locatDate == null) {
toast("can't get friends location info") setViewBeanLocation(latLng)
}
} }
} }
private fun removeOldViewingMarker() {
friendMarker?.remove()
friendMarker = null
}
private fun setViewBeanLocation(latLng: LatLng) {
map?.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 15f))
myMarker?.position = latLng
}
override fun onPause() { override fun onPause() {
super.onPause() super.onPause()
......
...@@ -37,7 +37,6 @@ class LocationPresenter( ...@@ -37,7 +37,6 @@ class LocationPresenter(
fun startUploadMyLocation() { fun startUploadMyLocation() {
if (uploadJob == null) { if (uploadJob == null) {
LogEx.logDebug(TAG, "startUploadMyLocation")
uploadJob = lifecycleCoroutineScope.launch(Dispatchers.IO) { uploadJob = lifecycleCoroutineScope.launch(Dispatchers.IO) {
while (isActive) { while (isActive) {
getGoogleServiceLocation() getGoogleServiceLocation()
...@@ -46,15 +45,6 @@ class LocationPresenter( ...@@ -46,15 +45,6 @@ class LocationPresenter(
if (latLng == null) { if (latLng == null) {
latLng = googleLocation latLng = googleLocation
} }
// if (BuildConfig.DEBUG) {
// latLng = LatLng(22.319275419461, 114.16934747047871)
// launch(Dispatchers.Main) {
// val device = AppPreferences.getInstance().getString("uuid", "")
// activity.toast("device=$device")
// delay(2000)
// activity.toast("Upload ${latLng.latitude} ${latLng.longitude}")
// }
// }
val power = activity.getBatteryLevel() val power = activity.getBatteryLevel()
latLng?.let { uploadMyLocation(latLng, power) } latLng?.let { uploadMyLocation(latLng, power) }
delay(30 * 1000L) delay(30 * 1000L)
......
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