Page Menu
Home
GitPull.it
Search
Configure Global Search
Log In
Files
F11305594
D218.1772734827.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D218.1772734827.diff
View Options
diff --git a/app/src/main/java/it/reyboz/bustorino/fragments/GeneralMapLibreFragment.kt b/app/src/main/java/it/reyboz/bustorino/fragments/GeneralMapLibreFragment.kt
--- a/app/src/main/java/it/reyboz/bustorino/fragments/GeneralMapLibreFragment.kt
+++ b/app/src/main/java/it/reyboz/bustorino/fragments/GeneralMapLibreFragment.kt
@@ -3,10 +3,12 @@
import android.animation.ValueAnimator
import android.annotation.SuppressLint
import android.content.Context
+import android.content.Context.LOCATION_SERVICE
import android.content.SharedPreferences
import android.content.res.ColorStateList
import android.graphics.Color
import android.location.Location
+import android.location.LocationManager
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
@@ -784,6 +786,11 @@
return bottomSheetBehavior.state == BottomSheetBehavior.STATE_EXPANDED
}
+ protected fun deviceHasGpsProvider(): Boolean{
+ val locManager = requireContext().getSystemService(LOCATION_SERVICE) as LocationManager
+ return locManager.allProviders.contains(LocationManager.GPS_PROVIDER)
+ }
+
companion object{
private const val DEBUG_TAG="GeneralMapLibreFragment"
diff --git a/app/src/main/java/it/reyboz/bustorino/fragments/MapLibreFragment.kt b/app/src/main/java/it/reyboz/bustorino/fragments/MapLibreFragment.kt
--- a/app/src/main/java/it/reyboz/bustorino/fragments/MapLibreFragment.kt
+++ b/app/src/main/java/it/reyboz/bustorino/fragments/MapLibreFragment.kt
@@ -101,7 +101,12 @@
if(lastLoc==null) lastLoc = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER)
else Log.d(DEBUG_TAG, "Got last location from cache")
- if (lastLoc != null) {
+ //FIRST CASE: I have no GPS
+ if( !locationManager.allProviders.contains(LocationManager.GPS_PROVIDER) ){
+ setMapLocationEnabled(false, false,false)
+
+ }
+ else if (lastLoc != null) {
if(LatLng(lastLoc.latitude, lastLoc.longitude).distanceTo(DEFAULT_LATLNG) <= MAX_DIST_KM*1000){
Log.d(DEBUG_TAG, "Showing the user position")
setMapLocationEnabled(true, true, false)
@@ -230,7 +235,7 @@
}
}
locationManager = requireActivity().getSystemService(Context.LOCATION_SERVICE) as LocationManager
- if (Permissions.bothLocationPermissionsGranted(requireContext())) {
+ if (Permissions.bothLocationPermissionsGranted(requireContext()) && deviceHasGpsProvider()) {
requestInitialUserLocation()
} else{
if (shouldShowRequestPermissionRationale(Manifest.permission.ACCESS_FINE_LOCATION)) {
@@ -759,13 +764,20 @@
}
-
+ /**
+ * Method used for enabling / disabling the location
+ */
private fun switchUserLocationStatus(view: View?){
- if(pendingLocationActivation || locationComponent.isLocationComponentEnabled) setMapLocationEnabled(false, false, true)
+ if(pendingLocationActivation || locationComponent.isLocationComponentEnabled)
+ setMapLocationEnabled(false, false, true)
else{
- pendingLocationActivation = true
- Log.d(DEBUG_TAG, "Request enable location")
- setMapLocationEnabled(true, false, true)
+ if(locationManager.allProviders.contains(LocationManager.GPS_PROVIDER)) {
+ pendingLocationActivation = true
+ Log.d(DEBUG_TAG, "Request enable location")
+ setMapLocationEnabled(true, false, true)
+ } else{
+ Log.w(DEBUG_TAG, "Cannot find location, no GPS")
+ }
}
}
diff --git a/app/src/main/java/it/reyboz/bustorino/fragments/NearbyStopsFragment.java b/app/src/main/java/it/reyboz/bustorino/fragments/NearbyStopsFragment.java
--- a/app/src/main/java/it/reyboz/bustorino/fragments/NearbyStopsFragment.java
+++ b/app/src/main/java/it/reyboz/bustorino/fragments/NearbyStopsFragment.java
@@ -260,10 +260,13 @@
@SuppressLint("MissingPermission")
private boolean requestLocationUpdates(){
if(Permissions.anyLocationPermissionsGranted(requireContext())) {
- locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
- 3000, 10.0f, fragmentLocationListener
- );
- fragmentLocationListener.isRegistered = true;
+ if (locManager.getAllProviders().contains(LocationManager.GPS_PROVIDER)) {
+ locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
+ 3000, 10.0f, fragmentLocationListener
+ );
+ fragmentLocationListener.isRegistered = true;
+ }
+ fragmentLocationListener.isRegistered = false;
return true;
} else return false;
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Mar 5, 19:20 (18 h, 11 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1715220
Default Alt Text
D218.1772734827.diff (4 KB)
Attached To
Mode
D218: Enable app to run without GPS on the devices
Attached
Detach File
Event Timeline
Log In to Comment