Commit 641b378a authored by wanglei's avatar wanglei

...

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