Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
L
location share white
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wanglei
location share white
Commits
20af04a0
Commit
20af04a0
authored
Oct 30, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...
parent
fbb79620
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
28 deletions
+59
-28
LocationMapActivity.kt
.../locationsharewhite/ui/locationmap/LocationMapActivity.kt
+39
-23
LocationPresenter.kt
...se/locationsharewhite/ui/locationmap/LocationPresenter.kt
+20
-5
No files found.
app/src/main/java/com/base/locationsharewhite/ui/locationmap/LocationMapActivity.kt
View file @
20af04a0
...
@@ -82,9 +82,10 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea
...
@@ -82,9 +82,10 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea
if
(
currentViewingBean
!=
viewingBean
)
{
if
(
currentViewingBean
!=
viewingBean
)
{
removeOldViewingMarker
()
removeOldViewingMarker
()
currentViewingBean
=
viewingBean
currentViewingBean
=
viewingBean
setViewingBeanMarker
(
15f
)
}
}
changeMarkerZIndex
(
false
)
setViewingBeanMarker
(
true
)
startGetLocationJob
()
startGetLocationJob
()
},
},
...
@@ -116,7 +117,7 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea
...
@@ -116,7 +117,7 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea
viewing
?.
locatDate
=
locatDate
viewing
?.
locatDate
=
locatDate
adapter
.
notifyDataSetChanged
()
adapter
.
notifyDataSetChanged
()
setViewingBeanMarker
()
setViewingBeanMarker
(
false
)
}
}
}
}
}
}
...
@@ -180,9 +181,8 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea
...
@@ -180,9 +181,8 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea
binding
.
llNoFriend
.
visibility
=
View
.
VISIBLE
binding
.
llNoFriend
.
visibility
=
View
.
VISIBLE
}
}
}
}
binding
.
ivLocation
.
setOnClickListener
{
binding
.
ivLocation
.
setOnClickListener
{
resetMyLocation
()
resetMyLocation
(
locationPresenter
.
getMyLocation
(),
true
,
true
)
}
}
binding
.
ivRefresh
.
setOnClickListener
{
binding
.
ivRefresh
.
setOnClickListener
{
startRefreshAnimation
()
startRefreshAnimation
()
...
@@ -223,35 +223,38 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea
...
@@ -223,35 +223,38 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea
override
fun
onMapReady
(
googleMap
:
GoogleMap
)
{
override
fun
onMapReady
(
googleMap
:
GoogleMap
)
{
map
=
googleMap
map
=
googleMap
LogEx
.
logDebug
(
TAG
,
"onMapReady"
)
LogEx
.
logDebug
(
TAG
,
"onMapReady"
)
val
flag
=
resetMyLocation
()
val
flag
=
resetMyLocation
(
locationPresenter
.
getMyLocation
(),
true
,
true
)
if
(!
flag
)
{
if
(!
flag
)
{
locationPresenter
.
getGoogleServiceLocation
()
locationPresenter
.
getGoogleServiceLocation
()
locationPresenter
.
oneShotLocationCallBack
=
{
locationPresenter
.
oneShotLocationCallBack
=
{
resetMyLocation
()
resetMyLocation
(
locationPresenter
.
getMyLocation
(),
true
,
true
)
}
}
}
}
locationPresenter
.
refreshLocationCallBack
=
{
resetMyLocation
(
it
,
false
,
false
)
}
}
}
private
fun
resetMyLocation
():
Boolean
{
private
fun
resetMyLocation
(
latLng
:
LatLng
?,
resetZoom
:
Boolean
,
changeZIndex
:
Boolean
):
Boolean
{
var
myLatLng
:
LatLng
?
=
getLatLngByLocationManager
()
if
(
changeZIndex
)
{
if
(
myLatLng
==
null
)
{
changeMarkerZIndex
(
true
)
myLatLng
=
locationPresenter
.
googleLocation
}
if
(
BuildConfig
.
DEBUG
)
{
if
(
myLatLng
==
null
)
{
toast
(
"can't get LatLng"
)
}
}
}
initMyLocationMarker
()
initMyLocationMarker
()
myLatLng
?.
let
{
latLng
?.
let
{
myMarker
?.
position
=
myLatLng
myMarker
?.
position
=
it
map
?.
moveCamera
(
CameraUpdateFactory
.
newLatLngZoom
(
myLatLng
,
15f
))
if
(
resetZoom
)
{
map
?.
moveCamera
(
CameraUpdateFactory
.
newLatLngZoom
(
it
,
15f
))
}
else
{
map
?.
moveCamera
(
CameraUpdateFactory
.
newLatLng
(
it
))
}
return
true
return
true
}
}
return
false
return
false
}
}
private
fun
initMyLocationMarker
()
{
private
fun
initMyLocationMarker
()
{
if
(
myMarker
==
null
)
{
if
(
myMarker
==
null
)
{
var
myLatLng
:
LatLng
?
=
getLatLngByLocationManager
()
var
myLatLng
:
LatLng
?
=
getLatLngByLocationManager
()
...
@@ -266,7 +269,7 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea
...
@@ -266,7 +269,7 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea
}
}
}
}
private
fun
setViewingBeanMarker
(
zoom
:
Float
?
=
null
)
{
private
fun
setViewingBeanMarker
(
resetZoom
:
Boolean
)
{
currentViewingBean
?.
let
{
viewingBean
->
currentViewingBean
?.
let
{
viewingBean
->
viewingBean
.
locatDate
?.
let
{
locatDate
->
viewingBean
.
locatDate
?.
let
{
locatDate
->
...
@@ -278,7 +281,7 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea
...
@@ -278,7 +281,7 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea
friendMarker
=
map
?.
addLocationMarker
(
friendAvatar
,
latLng
,
viewingBean
.
nickname
)
friendMarker
=
map
?.
addLocationMarker
(
friendAvatar
,
latLng
,
viewingBean
.
nickname
)
}
}
setView
BeanLocation
(
latLng
,
z
oom
)
setView
ingBeanLocation
(
latLng
,
resetZ
oom
)
}
}
}
}
}
}
...
@@ -288,11 +291,24 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea
...
@@ -288,11 +291,24 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea
friendMarker
=
null
friendMarker
=
null
}
}
private
fun
setViewBeanLocation
(
latLng
:
LatLng
,
zoom
:
Float
?
=
null
)
{
private
fun
setViewingBeanLocation
(
latLng
:
LatLng
,
resetZoom
:
Boolean
=
false
)
{
zoom
?.
let
{
if
(
resetZoom
)
{
map
?.
moveCamera
(
CameraUpdateFactory
.
newLatLngZoom
(
latLng
,
it
))
map
?.
moveCamera
(
CameraUpdateFactory
.
newLatLngZoom
(
latLng
,
15f
))
}
else
{
map
?.
moveCamera
(
CameraUpdateFactory
.
newLatLng
(
latLng
))
}
}
myMarker
?.
position
=
latLng
myMarker
?.
position
=
latLng
}
private
fun
changeMarkerZIndex
(
isShowMe
:
Boolean
)
{
if
(
isShowMe
)
{
myMarker
?.
zIndex
=
2f
friendMarker
?.
zIndex
=
1f
}
else
{
myMarker
?.
zIndex
=
1f
friendMarker
?.
zIndex
=
2f
}
}
}
...
...
app/src/main/java/com/base/locationsharewhite/ui/locationmap/LocationPresenter.kt
View file @
20af04a0
...
@@ -33,20 +33,35 @@ class LocationPresenter(
...
@@ -33,20 +33,35 @@ class LocationPresenter(
private
var
fusedLocationClient
:
FusedLocationProviderClient
=
LocationServices
.
getFusedLocationProviderClient
(
activity
)
private
var
fusedLocationClient
:
FusedLocationProviderClient
=
LocationServices
.
getFusedLocationProviderClient
(
activity
)
var
googleLocation
:
LatLng
?
=
null
var
googleLocation
:
LatLng
?
=
null
//一次性更新自己的位置
var
oneShotLocationCallBack
:
(()
->
Unit
)?
=
null
var
oneShotLocationCallBack
:
(()
->
Unit
)?
=
null
//刷新自己的位置
var
refreshLocationCallBack
:
((
latLng
:
LatLng
?)
->
Unit
)?
=
null
fun
getMyLocation
():
LatLng
?
{
var
latLng
=
activity
.
getLatLngByLocationManager
()
if
(
latLng
==
null
)
{
latLng
=
googleLocation
}
return
latLng
}
fun
startUploadMyLocation
()
{
fun
startUploadMyLocation
()
{
if
(
uploadJob
==
null
)
{
if
(
uploadJob
==
null
)
{
uploadJob
=
lifecycleCoroutineScope
.
launch
(
Dispatchers
.
IO
)
{
uploadJob
=
lifecycleCoroutineScope
.
launch
(
Dispatchers
.
IO
)
{
while
(
isActive
)
{
while
(
isActive
)
{
getGoogleServiceLocation
()
getGoogleServiceLocation
()
var
latLng
=
activity
.
getLatLngByLocationManager
()
val
latLng
=
getMyLocation
()
if
(
latLng
==
null
)
{
latLng
=
googleLocation
}
val
power
=
activity
.
getBatteryLevel
()
val
power
=
activity
.
getBatteryLevel
()
latLng
?.
let
{
uploadMyLocation
(
latLng
,
power
)
}
latLng
?.
let
{
launch
(
Dispatchers
.
Main
)
{
refreshLocationCallBack
?.
invoke
(
it
)
}
uploadMyLocation
(
latLng
,
power
)
}
delay
(
30
*
1000L
)
delay
(
30
*
1000L
)
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment