Skip to content

Commit 81e52ef

Browse files
committed
dry code better
1 parent c3839c4 commit 81e52ef

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

app/src/org/commcare/location/CommCareLocationController.kt

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,21 @@ fun isLocationFresh(location: Location, maxAgeMs: Long = DEFAULT_TIME_THRESHOLD)
3333

3434
fun shouldDiscardLocation(location: Location): Boolean {
3535
if(!isLocationFresh(location)) {
36-
Logger.exception(
37-
"Received a stale location",
38-
Exception(
39-
"Received a stale location with accuracy ${location.accuracy}" +
40-
" with time ${location.time}" + " and current device time ${System.currentTimeMillis()}"
41-
)
42-
)
36+
Logger.exception("Received a stale location", getStaleLocationException(location))
4337
return HiddenPreferences.shouldDiscardStaleLocations()
4438
}
4539
return false
4640
}
4741

42+
fun getStaleLocationException(location: Location): Throwable {
43+
Exception(
44+
"Stale location with accuracy ${location.accuracy}" +
45+
" with time ${location.time}" + " and current device time ${System.currentTimeMillis()}"
46+
)
47+
}
48+
4849
fun logStaleLocationSaved(location: Location) {
4950
if (!isLocationFresh(location, DEFAULT_TIME_THRESHOLD)) {
50-
Logger.exception(
51-
"Stale location saved in GPS capture",
52-
Throwable(
53-
"Saved a stale location with accuracy ${location.accuracy}" +
54-
" with time ${location.time}" + " and current device time ${System.currentTimeMillis()}"
55-
)
56-
)
51+
Logger.exception("Stale location saved in GPS capture", getStaleLocationException(location))
5752
}
5853
}

0 commit comments

Comments
 (0)