|
|
|
|
@ -68,6 +68,13 @@ open class PokerAnalyticsActivity : AppCompatActivity() { |
|
|
|
|
return realm |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Return if the location permission has been granted by the user |
|
|
|
|
*/ |
|
|
|
|
fun hasLocationPermissionGranted() : Boolean { |
|
|
|
|
return ContextCompat.checkSelfPermission(this, ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Ask for location permission |
|
|
|
|
*/ |
|
|
|
|
@ -78,7 +85,6 @@ open class PokerAnalyticsActivity : AppCompatActivity() { |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Ask for places request |
|
|
|
|
*/ |
|
|
|
|
@ -118,4 +124,25 @@ open class PokerAnalyticsActivity : AppCompatActivity() { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Find the current location |
|
|
|
|
*/ |
|
|
|
|
fun findCurrentLocation(callback: ((location: Location?) -> Unit)?) { |
|
|
|
|
if (LocationManager(this).databaseContainsLocationsWithCoordinates()) { |
|
|
|
|
if (ContextCompat.checkSelfPermission(this, ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { |
|
|
|
|
LocationManager(this).findNearestLocationFromUser(callback) |
|
|
|
|
} else { |
|
|
|
|
askForLocationPermission { granted -> |
|
|
|
|
if (granted) { |
|
|
|
|
LocationManager(this).findNearestLocationFromUser(callback) |
|
|
|
|
} else { |
|
|
|
|
callback?.invoke(null) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
callback?.invoke(null) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |