Skip to content

Commit c277cbd

Browse files
committed
WeatherUpdaterWorker: fix updateLocation if location is undefined
1 parent 0862342 commit c277cbd

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

Diff for: app/src/main/java/com/thewizrd/simpleweather/services/WeatherUpdaterWorker.kt

+4-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import androidx.localbroadcastmanager.content.LocalBroadcastManager
2525
import androidx.work.*
2626
import com.google.android.gms.location.*
2727
import com.thewizrd.shared_resources.AppState
28+
import com.thewizrd.shared_resources.locationdata.LocationData
2829
import com.thewizrd.shared_resources.remoteconfig.RemoteConfig
2930
import com.thewizrd.shared_resources.tzdb.TZDBCache
3031
import com.thewizrd.shared_resources.utils.*
@@ -455,7 +456,8 @@ class WeatherUpdaterWorker(context: Context, workerParams: WorkerParameters) : C
455456
val lastGPSLocData = settingsManager.getLastGPSLocData()
456457

457458
// Check previous location difference
458-
if (lastGPSLocData?.query != null && ConversionMethods.calculateHaversine(lastGPSLocData.latitude, lastGPSLocData.longitude, location.latitude, location.longitude).absoluteValue < 1600) {
459+
if (lastGPSLocData?.query != null && ConversionMethods.calculateHaversine(
460+
lastGPSLocData.latitude, lastGPSLocData.longitude, location.latitude, location.longitude).absoluteValue < 1600) {
459461
return@withContext false
460462
}
461463

@@ -480,8 +482,7 @@ class WeatherUpdaterWorker(context: Context, workerParams: WorkerParameters) : C
480482
}
481483

482484
// Save location as last known
483-
lastGPSLocData!!.setData(query_vm, location)
484-
settingsManager.saveLastGPSLocData(lastGPSLocData)
485+
settingsManager.saveLastGPSLocData(LocationData(query_vm, location))
485486
return@withContext true
486487
}
487488
}

Diff for: wearapp/src/main/java/com/thewizrd/simpleweather/services/WeatherUpdaterWorker.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import androidx.core.location.LocationManagerCompat
2424
import androidx.core.os.postDelayed
2525
import androidx.work.*
2626
import com.google.android.gms.location.*
27+
import com.thewizrd.shared_resources.locationdata.LocationData
2728
import com.thewizrd.shared_resources.remoteconfig.RemoteConfig
2829
import com.thewizrd.shared_resources.tzdb.TZDBCache
2930
import com.thewizrd.shared_resources.utils.*
@@ -405,8 +406,7 @@ class WeatherUpdaterWorker(context: Context, workerParams: WorkerParameters) : C
405406
}
406407

407408
// Save location as last known
408-
lastGPSLocData!!.setData(query_vm, location)
409-
settingsMgr.saveLastGPSLocData(lastGPSLocData)
409+
settingsMgr.saveLastGPSLocData(LocationData(query_vm, location))
410410
return@withContext true
411411
}
412412
}

0 commit comments

Comments
 (0)