mirror of
https://github.com/rt-bishop/Look4Sat.git
synced 2026-10-02 03:15:37 +00:00
Fixed satellite track exception crash
This commit is contained in:
1 parent
6926f87747
commit
eebe691419
4 files changed
+44
-7
No files matched your search
@@ -1,3 +1,20 @@
|
||||
/*
|
||||
* Look4Sat. Amateur radio satellite tracker and pass predictor.
|
||||
* Copyright (C) 2019-2021 Arty Bishop (bishop.arty@gmail.com)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rtbishop.look4sat.framework
|
||||
|
||||
import android.Manifest
|
||||
|
||||
@@ -68,6 +68,11 @@ class PreferencesSource @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
fun updatePosition(latitude: Double, longitude: Double) {
|
||||
val stationPosition = GeoPos(latitude, longitude)
|
||||
saveStationPosition(stationPosition)
|
||||
}
|
||||
|
||||
fun updatePositionFromGPS(): Boolean {
|
||||
return try {
|
||||
val location = locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER)
|
||||
|
||||
@@ -118,7 +118,7 @@ class MapFragment : Fragment(R.layout.fragment_map) {
|
||||
textLabelFontSize = 24
|
||||
textLabelBackgroundColor = Color.TRANSPARENT
|
||||
textLabelForegroundColor =
|
||||
ContextCompat.getColor(requireContext(), R.color.themeLight)
|
||||
ContextCompat.getColor(requireContext(), R.color.themeAccent)
|
||||
setTextIcon(it.key.params.name)
|
||||
setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_CENTER)
|
||||
try {
|
||||
|
||||
+21
-6
@@ -18,8 +18,12 @@
|
||||
package com.rtbishop.look4sat.presentation.settingsScreen
|
||||
|
||||
import android.Manifest
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.location.Location
|
||||
import android.location.LocationListener
|
||||
import android.location.LocationManager
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.text.method.LinkMovementMethod
|
||||
@@ -42,7 +46,7 @@ import dagger.hilt.android.AndroidEntryPoint
|
||||
import javax.inject.Inject
|
||||
|
||||
@AndroidEntryPoint
|
||||
class SettingsFragment : Fragment(R.layout.fragment_settings) {
|
||||
class SettingsFragment : Fragment(R.layout.fragment_settings), LocationListener {
|
||||
|
||||
@Inject
|
||||
lateinit var preferences: PreferencesSource
|
||||
@@ -173,11 +177,13 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
|
||||
}
|
||||
|
||||
private fun updatePositionFromGPS() {
|
||||
val locPermString = Manifest.permission.ACCESS_FINE_LOCATION
|
||||
val locPermResult = ContextCompat.checkSelfPermission(requireContext(), locPermString)
|
||||
if (locPermResult == PackageManager.PERMISSION_GRANTED) {
|
||||
if (preferences.updatePositionFromGPS()) {
|
||||
showSnack(getString(R.string.pref_pos_success))
|
||||
val manager = requireContext().getSystemService(Context.LOCATION_SERVICE) as LocationManager
|
||||
val provider = LocationManager.NETWORK_PROVIDER
|
||||
val permission = Manifest.permission.ACCESS_COARSE_LOCATION
|
||||
val result = ContextCompat.checkSelfPermission(requireContext(), permission)
|
||||
if (result == PackageManager.PERMISSION_GRANTED) {
|
||||
if (manager.isProviderEnabled(provider)) {
|
||||
manager.requestLocationUpdates(provider, 0L, 0f, this)
|
||||
} else {
|
||||
showSnack(getString(R.string.pref_pos_gps_null))
|
||||
}
|
||||
@@ -204,4 +210,13 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
|
||||
_binding = null
|
||||
super.onDestroyView()
|
||||
}
|
||||
|
||||
override fun onLocationChanged(location: Location) {
|
||||
val manager = requireContext().getSystemService(Context.LOCATION_SERVICE) as LocationManager
|
||||
manager.removeUpdates(this)
|
||||
val latitude = location.latitude.round(4)
|
||||
val longitude = location.longitude.round(4)
|
||||
preferences.updatePosition(latitude, longitude)
|
||||
showSnack(getString(R.string.pref_pos_success))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user