|
|
|
@ -18,6 +18,7 @@ open class PokerAnalyticsActivity : AppCompatActivity() { |
|
|
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
companion object { |
|
|
|
const val PERMISSION_REQUEST_ACCESS_FINE_LOCATION = 1000 |
|
|
|
const val PERMISSION_REQUEST_ACCESS_FINE_LOCATION = 1000 |
|
|
|
|
|
|
|
const val PLAY_SERVICES_RESOLUTION_REQUEST = 2000 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private val realm = Realm.getDefaultInstance() |
|
|
|
private val realm = Realm.getDefaultInstance() |
|
|
|
@ -71,7 +72,7 @@ open class PokerAnalyticsActivity : AppCompatActivity() { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Return if the location permission has been granted by the user |
|
|
|
* Return if the location permission has been granted by the user |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
fun hasLocationPermissionGranted() : Boolean { |
|
|
|
fun hasLocationPermissionGranted(): Boolean { |
|
|
|
return ContextCompat.checkSelfPermission(this, ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED |
|
|
|
return ContextCompat.checkSelfPermission(this, ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -127,22 +128,18 @@ open class PokerAnalyticsActivity : AppCompatActivity() { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Find the current location |
|
|
|
* Find the current location |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
fun findCurrentLocation(callback: ((location: Location?) -> Unit)?) { |
|
|
|
fun findCurrentLocation(callback: ((location: android.location.Location?) -> Unit)?) { |
|
|
|
if (LocationManager(this).databaseContainsLocationsWithCoordinates()) { |
|
|
|
|
|
|
|
if (ContextCompat.checkSelfPermission(this, ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { |
|
|
|
if (ContextCompat.checkSelfPermission(this, ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { |
|
|
|
LocationManager(this).findNearestLocationFromUser(callback) |
|
|
|
LocationManager(this).findCurrentLocation(callback) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
askForLocationPermission { granted -> |
|
|
|
askForLocationPermission { granted -> |
|
|
|
if (granted) { |
|
|
|
if (granted) { |
|
|
|
LocationManager(this).findNearestLocationFromUser(callback) |
|
|
|
LocationManager(this).findCurrentLocation(callback) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
callback?.invoke(null) |
|
|
|
callback?.invoke(null) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
|
|
|
|
callback?.invoke(null) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |