|
|
|
@ -8,16 +8,20 @@ import android.view.MenuItem |
|
|
|
import androidx.appcompat.app.AppCompatActivity |
|
|
|
import androidx.appcompat.app.AppCompatActivity |
|
|
|
import androidx.core.app.ActivityCompat |
|
|
|
import androidx.core.app.ActivityCompat |
|
|
|
import androidx.core.content.ContextCompat |
|
|
|
import androidx.core.content.ContextCompat |
|
|
|
|
|
|
|
import com.google.android.gms.common.ConnectionResult |
|
|
|
|
|
|
|
import com.google.android.gms.common.GoogleApiAvailability |
|
|
|
import com.google.android.libraries.places.api.model.PlaceLikelihood |
|
|
|
import com.google.android.libraries.places.api.model.PlaceLikelihood |
|
|
|
import io.realm.Realm |
|
|
|
import io.realm.Realm |
|
|
|
import net.pokeranalytics.android.model.realm.Location |
|
|
|
import net.pokeranalytics.android.model.realm.Location |
|
|
|
import net.pokeranalytics.android.util.LocationManager |
|
|
|
import net.pokeranalytics.android.util.LocationManager |
|
|
|
|
|
|
|
import timber.log.Timber |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
open class PokerAnalyticsActivity : AppCompatActivity() { |
|
|
|
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 +75,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 +131,36 @@ 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).findCurrentLocation(callback) |
|
|
|
LocationManager(this).findNearestLocationFromUser(callback) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
askForLocationPermission { granted -> |
|
|
|
askForLocationPermission { granted -> |
|
|
|
if (granted) { |
|
|
|
if (granted) { |
|
|
|
LocationManager(this).findCurrentLocation(callback) |
|
|
|
LocationManager(this).findNearestLocationFromUser(callback) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
callback?.invoke(null) |
|
|
|
callback?.invoke(null) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
|
|
|
|
callback?.invoke(null) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Check the Google Play Services |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
fun checkPlayServices(): Boolean { |
|
|
|
|
|
|
|
val googleAPI = GoogleApiAvailability.getInstance() |
|
|
|
|
|
|
|
val result = googleAPI.isGooglePlayServicesAvailable(this) |
|
|
|
|
|
|
|
Timber.d("checkPlayServices: $result") |
|
|
|
|
|
|
|
if (result != ConnectionResult.SUCCESS) { |
|
|
|
|
|
|
|
if (googleAPI.isUserResolvableError(result)) { |
|
|
|
|
|
|
|
googleAPI.getErrorDialog(this, result, PLAY_SERVICES_RESOLUTION_REQUEST).show() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return false |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |