Skip to content

Commit f482fb6

Browse files
committed
Build 154
- Added Last Location provider indicator instead of removing last location entirely - Fixed few crashes related to maps panel and marker
1 parent 20da966 commit f482fb6

File tree

4 files changed

+44
-23
lines changed

4 files changed

+44
-23
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ android {
5050

5151
compileSdkVersion 31
5252

53-
def appVersionCode = 153
54-
def appVersionName = "//${appVersionCode}_final"
53+
def appVersionCode = 154
54+
def appVersionName = "build${appVersionCode}_final"
5555

5656
defaultConfig {
5757
applicationId "app.simple.positional"
@@ -128,10 +128,10 @@ dependencies {
128128
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
129129

130130
// AndroidX
131-
implementation 'androidx.appcompat:appcompat:1.3.1'
132-
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
131+
implementation 'androidx.appcompat:appcompat:1.4.0'
132+
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
133133
implementation 'androidx.core:core-ktx:1.7.0'
134-
implementation 'androidx.fragment:fragment-ktx:1.3.6'
134+
implementation 'androidx.fragment:fragment-ktx:1.4.0'
135135
implementation 'androidx.dynamicanimation:dynamicanimation:1.0.0'
136136
implementation 'androidx.webkit:webkit:1.4.0'
137137
implementation 'androidx.recyclerview:recyclerview:1.2.1'
@@ -154,9 +154,9 @@ dependencies {
154154
implementation 'com.github.vipulasri:timelineview:1.1.5'
155155

156156
// Room components
157-
implementation "androidx.room:room-ktx:2.4.0-beta01"
158-
kapt "androidx.room:room-compiler:2.4.0-beta01"
159-
androidTestImplementation "androidx.room:room-testing:2.4.0-beta01"
157+
implementation "androidx.room:room-ktx:2.4.0-beta02"
158+
kapt "androidx.room:room-compiler:2.4.0-beta02"
159+
androidTestImplementation "androidx.room:room-testing:2.4.0-beta02"
160160

161161
// Leak Canary -- debugImplementation because LeakCanary should only run in debug builds.
162162
// debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.5'

app/src/main/java/app/simple/positional/services/FusedLocationService.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@ class FusedLocationService : Service() {
4242

4343
fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(applicationContext)
4444
locationRequest = LocationRequest.create()
45-
.setInterval(delay)
46-
.setFastestInterval(delay)
47-
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
45+
.setInterval(delay)
46+
.setFastestInterval(delay)
47+
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
48+
49+
requestLastLocation()
4850

4951
locationCallback = object : LocationCallback() {
5052
override fun onLocationResult(result: LocationResult) {
@@ -60,8 +62,6 @@ class FusedLocationService : Service() {
6062
}
6163
}
6264

63-
requestCurrentLocation()
64-
6565
broadcastReceiver = object : BroadcastReceiver() {
6666
override fun onReceive(context: Context?, intent: Intent?) {
6767
Intent().also {
@@ -76,9 +76,9 @@ class FusedLocationService : Service() {
7676
}
7777

7878
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
79+
requestLastLocation()
7980
if (!handlerThread.isAlive) {
8081
handlerThread.start()
81-
requestCurrentLocation()
8282
}
8383
return START_REDELIVER_INTENT
8484
}
@@ -87,6 +87,7 @@ class FusedLocationService : Service() {
8787
if (PermissionUtils.checkPermission(applicationContext)) {
8888
fusedLocationProviderClient.lastLocation.addOnCompleteListener {
8989
if (it.isSuccessful && it.result.isNotNull()) {
90+
it.result.provider = "Last Location"
9091
broadcastLocation(it.result)
9192
}
9293

app/src/main/java/app/simple/positional/services/LocationService.kt

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package app.simple.positional.services
22

33
import android.app.Service
44
import android.content.Intent
5-
import android.location.GnssStatus
65
import android.location.Location
76
import android.location.LocationListener
87
import android.location.LocationManager
@@ -30,7 +29,7 @@ class LocationService : Service(), LocationListener {
3029
}
3130

3231
override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int {
33-
postLocationRunnable()
32+
requestLastKnownLocation()
3433
return START_REDELIVER_INTENT
3534
}
3635

@@ -58,7 +57,7 @@ class LocationService : Service(), LocationListener {
5857
}
5958

6059
override fun onProviderEnabled(provider: String) {
61-
postLocationRunnable()
60+
requestLastKnownLocation()
6261
Intent().also { intent ->
6362
intent.action = "provider"
6463
intent.putExtra("location_provider", provider)
@@ -82,6 +81,32 @@ class LocationService : Service(), LocationListener {
8281
}
8382
}
8483

84+
private fun requestLastKnownLocation() {
85+
if (PermissionUtils.checkPermission(applicationContext)) {
86+
var location: Location? = null
87+
88+
when {
89+
locationManager!!.isProviderEnabled(LocationManager.GPS_PROVIDER) -> {
90+
location = locationManager?.getLastKnownLocation(LocationManager.GPS_PROVIDER)
91+
}
92+
locationManager!!.isProviderEnabled(LocationManager.NETWORK_PROVIDER) -> {
93+
location = locationManager?.getLastKnownLocation(LocationManager.NETWORK_PROVIDER)
94+
}
95+
locationManager!!.isProviderEnabled(LocationManager.PASSIVE_PROVIDER) -> {
96+
location = locationManager?.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER)
97+
}
98+
}
99+
100+
if (location.isNull()) {
101+
handler.post(locationUpdater)
102+
} else {
103+
location?.provider = "Last Location"
104+
onLocationChanged(location!!)
105+
handler.post(locationUpdater)
106+
}
107+
}
108+
}
109+
85110
private fun requestLocation() {
86111
if (PermissionUtils.checkPermission(applicationContext)) {
87112
when {
@@ -97,9 +122,4 @@ class LocationService : Service(), LocationListener {
97122
}
98123
}
99124
}
100-
101-
private fun postLocationRunnable() {
102-
handler.removeCallbacks(locationUpdater)
103-
handler.post(locationUpdater)
104-
}
105125
}

0 commit comments

Comments
 (0)