mirror of
https://github.com/atsunatsu/Look4Sat.git
synced 2026-10-02 19:17:21 +00:00
Minor fixes to location and DB
This commit is contained in:
1 parent
622118e87d
commit
5cdd3fdc46
3 files changed
+27
-26
No files matched your search
@@ -65,7 +65,7 @@ class PersistenceModule {
|
||||
@Singleton
|
||||
@Provides
|
||||
fun provideSatelliteDb(context: Context): SatelliteDb {
|
||||
return Room.databaseBuilder(context, SatelliteDb::class.java, "satellites")
|
||||
return Room.databaseBuilder(context, SatelliteDb::class.java, "satDb")
|
||||
.build()
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,6 @@
|
||||
|
||||
package com.rtbishop.look4sat.ui
|
||||
|
||||
import android.location.LocationManager
|
||||
import android.net.Uri
|
||||
import androidx.lifecycle.*
|
||||
import com.github.amsacode.predict4java.GroundStationPosition
|
||||
@@ -70,20 +69,12 @@ class SharedViewModel @Inject constructor(
|
||||
}
|
||||
|
||||
fun updatePosition() {
|
||||
val provider = LocationManager.PASSIVE_PROVIDER
|
||||
try {
|
||||
val location = prefsManager.locationManager.getLastKnownLocation(provider)
|
||||
location.let {
|
||||
if (it == null) {
|
||||
_gsp.postValue(Result.Error(IllegalArgumentException()))
|
||||
} else {
|
||||
val gsp = GroundStationPosition(it.latitude, it.longitude, it.altitude)
|
||||
prefsManager.setPosition(gsp)
|
||||
_gsp.postValue(Result.Success(gsp))
|
||||
}
|
||||
}
|
||||
} catch (e: SecurityException) {
|
||||
_gsp.postValue(Result.Error(e))
|
||||
val lastLoc = prefsManager.getLastKnownLocation()
|
||||
if (lastLoc == null) {
|
||||
_gsp.postValue(Result.Error(Exception()))
|
||||
} else {
|
||||
val gsp = GroundStationPosition(lastLoc.latitude, lastLoc.longitude, lastLoc.altitude)
|
||||
_gsp.postValue(Result.Success(gsp))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
package com.rtbishop.look4sat.utility
|
||||
|
||||
import android.content.SharedPreferences
|
||||
import android.location.Location
|
||||
import android.location.LocationManager
|
||||
import androidx.core.content.edit
|
||||
import com.github.amsacode.predict4java.GroundStationPosition
|
||||
@@ -27,7 +28,7 @@ import javax.inject.Inject
|
||||
|
||||
class PrefsManager @Inject constructor(
|
||||
private val preferences: SharedPreferences,
|
||||
val locationManager: LocationManager
|
||||
private val locationManager: LocationManager
|
||||
) {
|
||||
private val keyHoursAhead = "hoursAhead"
|
||||
private val keyMinElevation = "minEl"
|
||||
@@ -66,6 +67,24 @@ class PrefsManager @Inject constructor(
|
||||
return GroundStationPosition(lat, lon, alt)
|
||||
}
|
||||
|
||||
fun getLastKnownLocation(): Location? {
|
||||
val provPassive = LocationManager.PASSIVE_PROVIDER
|
||||
return try {
|
||||
val location = locationManager.getLastKnownLocation(provPassive)
|
||||
location?.let {
|
||||
preferences.edit {
|
||||
putString(keyLatitude, location.latitude.toString())
|
||||
putString(keyLongitude, location.longitude.toString())
|
||||
putString(keyAltitude, location.altitude.toString())
|
||||
apply()
|
||||
}
|
||||
}
|
||||
location
|
||||
} catch (e: SecurityException) {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
fun setHoursAhead(hours: Int) {
|
||||
preferences.edit {
|
||||
putInt(keyHoursAhead, hours)
|
||||
@@ -80,15 +99,6 @@ class PrefsManager @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
fun setPosition(gsp: GroundStationPosition) {
|
||||
preferences.edit {
|
||||
putString(keyLatitude, gsp.latitude.toString())
|
||||
putString(keyLongitude, gsp.longitude.toString())
|
||||
putString(keyAltitude, gsp.heightAMSL.toString())
|
||||
apply()
|
||||
}
|
||||
}
|
||||
|
||||
fun getTleSources(): Set<String> {
|
||||
return preferences.getStringSet(keyTleSources, null) ?: setOf(defaultTleUrl)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user