mirror of
https://github.com/atsunatsu/Look4Sat.git
synced 2026-10-02 03:15:37 +00:00
Switched to android.location api, removed google play services dependency
This commit is contained in:
1 parent
ec64f30c79
commit
220f13d22a
5 files changed
+14
-16
No files matched your search
@@ -85,7 +85,4 @@ dependencies {
|
||||
|
||||
// predict4java
|
||||
implementation "com.github.davidmoten:predict4java:$predict4java"
|
||||
|
||||
// location
|
||||
implementation "com.google.android.gms:play-services-location:$google_play"
|
||||
}
|
||||
@@ -22,7 +22,7 @@ package com.rtbishop.look4sat
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.location.Location
|
||||
import android.location.LocationManager
|
||||
import android.util.Log
|
||||
import androidx.core.content.edit
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
@@ -32,7 +32,6 @@ import androidx.lifecycle.viewModelScope
|
||||
import com.github.amsacode.predict4java.GroundStationPosition
|
||||
import com.github.amsacode.predict4java.SatNotFoundException
|
||||
import com.github.amsacode.predict4java.TLE
|
||||
import com.google.android.gms.location.FusedLocationProviderClient
|
||||
import com.rtbishop.look4sat.predict4kotlin.PassPredictor
|
||||
import com.rtbishop.look4sat.repo.Repository
|
||||
import com.rtbishop.look4sat.repo.SatPass
|
||||
@@ -79,7 +78,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
||||
private var calculationJob: Job? = null
|
||||
|
||||
@Inject
|
||||
lateinit var locationClient: FusedLocationProviderClient
|
||||
lateinit var locationManager: LocationManager
|
||||
@Inject
|
||||
lateinit var preferences: SharedPreferences
|
||||
@Inject
|
||||
@@ -109,8 +108,11 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
||||
_gsp.postValue(GroundStationPosition(lat, lon, alt))
|
||||
}
|
||||
|
||||
fun getCurrentLocation() {
|
||||
locationClient.lastLocation.addOnSuccessListener { location: Location? ->
|
||||
fun updateLocation() {
|
||||
val passiveProvider = LocationManager.PASSIVE_PROVIDER
|
||||
try {
|
||||
val location = locationManager.getLastKnownLocation(passiveProvider)
|
||||
|
||||
val lat = location?.latitude ?: 0.0
|
||||
val lon = location?.longitude ?: 0.0
|
||||
val alt = location?.altitude ?: 0.0
|
||||
@@ -123,6 +125,8 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
||||
}
|
||||
_gsp.postValue(GroundStationPosition(lat, lon, alt))
|
||||
_debugMessage.postValue(app.getString(R.string.update_loc_success))
|
||||
} catch (e: SecurityException) {
|
||||
_debugMessage.postValue(app.getString(R.string.err_no_permissions))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,9 +21,8 @@ package com.rtbishop.look4sat.di
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.location.LocationManager
|
||||
import androidx.preference.PreferenceManager
|
||||
import com.google.android.gms.location.FusedLocationProviderClient
|
||||
import com.google.android.gms.location.LocationServices
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import javax.inject.Singleton
|
||||
@@ -39,7 +38,7 @@ class AndroidModule {
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
fun provideLocationClient(context: Context): FusedLocationProviderClient {
|
||||
return LocationServices.getFusedLocationProviderClient(context)
|
||||
fun provideLocationManager(context: Context): LocationManager {
|
||||
return context.getSystemService(Context.LOCATION_SERVICE) as LocationManager
|
||||
}
|
||||
}
|
||||
@@ -169,7 +169,7 @@ class MainActivity : AppCompatActivity() {
|
||||
ActivityCompat.requestPermissions(this, arrayOf(permLocation), permLocationCode)
|
||||
}
|
||||
} else {
|
||||
viewModel.getCurrentLocation()
|
||||
viewModel.updateLocation()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ class MainActivity : AppCompatActivity() {
|
||||
when (reqCode) {
|
||||
permLocationCode -> {
|
||||
if (res.isNotEmpty() && res[0] == permGranted) {
|
||||
viewModel.getCurrentLocation()
|
||||
viewModel.updateLocation()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,6 +61,4 @@ ext {
|
||||
dagger = '2.25.2'
|
||||
|
||||
predict4java = '1.3.1'
|
||||
|
||||
google_play = '17.0.0'
|
||||
}
|
||||
Reference in new issue
Block a user