Remove permission launcher from MapFragment, already in MainActivity.

This commit is contained in:
voussoir 2023-12-24 22:20:43 -08:00
parent 47c338f38f
commit eb1ad45c4c
2 changed files with 2 additions and 22 deletions

View file

@ -47,6 +47,7 @@ class MainActivity: AppCompatActivity()
/* Overrides onCreate from AppCompatActivity */
override fun onCreate(savedInstanceState: Bundle?)
{
Log.i("VOUSSOIR", "MainActivity.onCreate")
trackbook = (applicationContext as Trackbook)
super.onCreate(savedInstanceState)
request_permissions(this)
@ -125,6 +126,7 @@ class MainActivity: AppCompatActivity()
/* Overrides onDestroy from AppCompatActivity */
override fun onDestroy()
{
Log.i("VOUSSOIR", "MainActivity.onDestroy")
super.onDestroy()
// unregister listener for changes in shared preferences
PreferencesHelper.unregisterPreferenceChangeListener(sharedPreferenceChangeListener)

View file

@ -237,11 +237,6 @@ class MapFragment : Fragment()
{
Log.i("VOUSSOIR", "MapFragment.onStart")
super.onStart()
// request location permission if denied
if (ContextCompat.checkSelfPermission(activity as Context, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_DENIED)
{
requestLocationPermissionLauncher.launch(Manifest.permission.ACCESS_FINE_LOCATION)
}
activity?.bindService(Intent(activity, TrackerService::class.java), tracker_service_connection, Context.BIND_AUTO_CREATE)
handler.post(redraw_runnable)
}
@ -313,23 +308,6 @@ class MapFragment : Fragment()
handler.removeCallbacks(redraw_runnable)
}
private val requestLocationPermissionLauncher = registerForActivityResult(RequestPermission()) { isGranted: Boolean ->
if (isGranted)
{
// permission was granted - re-bind service
activity?.unbindService(tracker_service_connection)
activity?.bindService(Intent(activity, TrackerService::class.java), tracker_service_connection, Context.BIND_AUTO_CREATE)
Log.i("VOUSSOIR", "Request result: Location permission has been granted.")
}
else
{
// permission denied - unbind service
activity?.unbindService(tracker_service_connection)
}
val gpsProviderActive = if (tracker_service == null) false else tracker_service!!.gpsProviderActive
val networkProviderActive = if (tracker_service == null) false else tracker_service!!.networkProviderActive
}
private fun startTracking()
{
// start service via intent so that it keeps running after unbind