Skip to content

Commit

Permalink
Update gps check
Browse files Browse the repository at this point in the history
  • Loading branch information
kylecorry31 committed Sep 28, 2020
1 parent 61cccda commit 1a0a318
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 10 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

group = 'com.kylecorry'
version = '1.0.5'
version = '1.0.6'

android {
compileSdkVersion 30

defaultConfig {
minSdkVersion 23
targetSdkVersion 30
versionCode 6
versionCode 7
versionName version

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ class AstronomyService : IAstronomyService {
)
}

override fun isSunUp(
time: ZonedDateTime,
location: Coordinate,
withRefraction: Boolean
): Boolean {
return getSunAltitude(time, location, withRefraction) > 0
}

override fun getMoonEvents(
date: ZonedDateTime, location: Coordinate,
withRefraction: Boolean
Expand Down Expand Up @@ -158,4 +166,12 @@ class AstronomyService : IAstronomyService {
return Astro.getMoonPhase(date)
}

override fun isMoonUp(
time: ZonedDateTime,
location: Coordinate,
withRefraction: Boolean
): Boolean {
return getMoonAltitude(time, location, withRefraction) > 0
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ interface IAstronomyService {
withRefraction: Boolean = false
): ZonedDateTime?

fun isSunUp(time: ZonedDateTime, location: Coordinate, withRefraction: Boolean = false): Boolean {
return getSunAltitude(time, location, withRefraction) > 0
}

fun isSunUp(time: ZonedDateTime, location: Coordinate, withRefraction: Boolean = false): Boolean

// MOON
fun getMoonEvents(date: ZonedDateTime, location: Coordinate, withRefraction: Boolean = false): RiseSetTransitTimes
Expand All @@ -45,8 +42,6 @@ interface IAstronomyService {
fun getNextMoonrise(time: ZonedDateTime, location: Coordinate, withRefraction: Boolean = false): ZonedDateTime?
fun getMoonPhase(date: ZonedDateTime): MoonPhase

fun isMoonUp(time: ZonedDateTime, location: Coordinate, withRefraction: Boolean = false): Boolean {
return getMoonAltitude(time, location, withRefraction) > 0
}
fun isMoonUp(time: ZonedDateTime, location: Coordinate, withRefraction: Boolean = false): Boolean

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import android.content.Context
import android.content.pm.PackageManager
import android.hardware.Sensor
import android.hardware.SensorManager
import android.location.LocationManager
import androidx.core.content.getSystemService
import com.kylecorry.trailsensecore.infrastructure.system.PermissionUtils

class SensorChecker(private val context: Context) {

Expand All @@ -16,7 +18,17 @@ class SensorChecker(private val context: Context) {
}

fun hasGPS(): Boolean {
return context.checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
if (!PermissionUtils.isLocationEnabled(context)) {
return false
}

val lm = context.getSystemService<LocationManager>()
try {
return lm?.isProviderEnabled(LocationManager.GPS_PROVIDER) ?: false
} catch (e: Exception) {
// Do nothing
}
return false
}

fun hasGravity(): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,14 @@ internal class SimpleLocationListener(private val onLocationChangedFn: (location
override fun onLocationChanged(location: Location) {
onLocationChangedFn.invoke(location)
}

override fun onStatusChanged(provider: String?, status: Int, extras: Bundle?) {
}

override fun onProviderDisabled(provider: String) {
}

override fun onProviderEnabled(provider: String) {

}
}

0 comments on commit 1a0a318

Please sign in to comment.