master
y20k 2020-09-02 16:00:08 +02:00
parent cdcd925930
commit 2776f00eaa
No known key found for this signature in database
GPG Key ID: 824D4259F41FAFF6
4 changed files with 21 additions and 16 deletions

View File

@ -52,7 +52,7 @@ class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// todo remove after testing finished
// todo: remove after testing finished
if (BuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
StrictMode.setVmPolicy(
VmPolicy.Builder()

View File

@ -138,6 +138,7 @@ class MapFragment : Fragment(), YesNoDialog.YesNoDialogListener, MapOverlayHelpe
super.onStop()
// unbind from TrackerService
activity?.unbindService(connection)
handleServiceUnbind()
}
@ -201,6 +202,17 @@ class MapFragment : Fragment(), YesNoDialog.YesNoDialogListener, MapOverlayHelpe
}
/* Handles state when service is being unbound */
private fun handleServiceUnbind() {
bound = false
// unregister listener for changes in shared preferences
PreferenceManager.getDefaultSharedPreferences(activity as Context).unregisterOnSharedPreferenceChangeListener(sharedPreferenceChangeListener)
// stop receiving location updates
handler.removeCallbacks(periodicLocationRequestRunnable)
}
/* Starts / pauses tracking and toggles the recording sub menu_bottom_navigation */
private fun handleTrackingManagementMenu() {
when (trackingState) {
@ -285,11 +297,8 @@ class MapFragment : Fragment(), YesNoDialog.YesNoDialogListener, MapOverlayHelpe
handler.postDelayed(periodicLocationRequestRunnable, 0)
}
override fun onServiceDisconnected(arg0: ComponentName) {
bound = false
// unregister listener for changes in shared preferences
PreferenceManager.getDefaultSharedPreferences(activity as Context).unregisterOnSharedPreferenceChangeListener(sharedPreferenceChangeListener)
// stop receiving location updates
handler.removeCallbacks(periodicLocationRequestRunnable)
// service has crashed, or was killed by the system
handleServiceUnbind()
}
}
/*

View File

@ -247,11 +247,6 @@ class TrackerService(): Service(), CoroutineScope, SensorEventListener {
/* Stop tracking location */
fun stopTracking() {
// stop receiving location updates - if app is not bound (= visible)
if (!bound) {
removeGpsLocationListener()
removeGpsLocationListener()
}
// save state
track.recordingStop = GregorianCalendar.getInstance().time
trackingState = Keys.STATE_TRACKING_STOPPED
@ -327,6 +322,7 @@ class TrackerService(): Service(), CoroutineScope, SensorEventListener {
// check if already registered
if (!gpsLocationListenerRegistered) {
// check if Network provider is available
gpsProviderActive = LocationHelper.isGpsEnabled(locationManager)
if (gpsProviderActive) {
// check for location permission
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
@ -351,6 +347,7 @@ class TrackerService(): Service(), CoroutineScope, SensorEventListener {
// check if already registered
if (!networkLocationListenerRegistered) {
// check if Network provider is available
networkProviderActive = LocationHelper.isNetworkEnabled(locationManager)
if (networkProviderActive && !gpsOnly) {
// check for location permission
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {

View File

@ -207,14 +207,13 @@ data class MapFragmentLayoutHolder(private var context: Context, private var mar
if (ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_DENIED) {
// CASE: Location permission not granted
locationErrorBar.setText(R.string.snackbar_message_location_permission_denied)
locationErrorBar.show()
if (!locationErrorBar.isShown) locationErrorBar.show()
} else if (!gpsProviderActive && !networkProviderActive) {
// CASE: Location setting is off
locationErrorBar.setText(R.string.snackbar_message_location_offline)
locationErrorBar.show()
} else if (locationErrorBar.isShown) {
// CASE: Snackbar is visible but unnecessary
locationErrorBar.dismiss()
if (!locationErrorBar.isShown) locationErrorBar.show()
} else {
if (locationErrorBar.isShown) locationErrorBar.dismiss()
}
}