Skip to content

Commit

Permalink
[] -- Check for Permissons
Browse files Browse the repository at this point in the history
  • Loading branch information
Isanz committed May 9, 2024
1 parent 1855264 commit 196e2d4
Showing 1 changed file with 33 additions and 8 deletions.
41 changes: 33 additions & 8 deletions app/src/main/java/com/isanz/inmomarket/ui/search/SearchFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.isanz.inmomarket.ui.search


import android.Manifest
import android.annotation.SuppressLint
import android.content.Context
import android.content.pm.PackageManager
import android.graphics.Bitmap
Expand Down Expand Up @@ -79,12 +78,7 @@ class SearchFragment : Fragment(), OnMapReadyCallback {
requireContext(), Manifest.permission.ACCESS_COARSE_LOCATION
) != PackageManager.PERMISSION_GRANTED
) {
requestPermissions(
arrayOf(
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION
), Constants.LOCATION_PERMISSION_REQUEST_CODE
)

return
}
enableUserLocation()
Expand All @@ -103,9 +97,24 @@ class SearchFragment : Fragment(), OnMapReadyCallback {
}
}

@SuppressLint("MissingPermission")
private fun enableUserLocation() {
if (allowUbication) {
if (ActivityCompat.checkSelfPermission(
requireContext(),
Manifest.permission.ACCESS_FINE_LOCATION
) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(
requireContext(),
Manifest.permission.ACCESS_COARSE_LOCATION
) != PackageManager.PERMISSION_GRANTED
) {
requestPermissions(
arrayOf(
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION
), Constants.LOCATION_PERMISSION_REQUEST_CODE
)
return
}
mMap.isMyLocationEnabled = true
mMap.isMyLocationEnabled = true
setMapLocationToUserLocation()
Expand All @@ -117,6 +126,22 @@ class SearchFragment : Fragment(), OnMapReadyCallback {
}

private fun setMapLocationToUserLocation() {
if (ActivityCompat.checkSelfPermission(
requireContext(),
Manifest.permission.ACCESS_FINE_LOCATION
) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(
requireContext(),
Manifest.permission.ACCESS_COARSE_LOCATION
) != PackageManager.PERMISSION_GRANTED
) {
requestPermissions(
arrayOf(
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION
), Constants.LOCATION_PERMISSION_REQUEST_CODE
)
return
}
fusedLocationClient.lastLocation.addOnSuccessListener { location ->
if (location != null) {
val currentLatLng = LatLng(location.latitude, location.longitude)
Expand Down

0 comments on commit 196e2d4

Please sign in to comment.