Skip to content

Commit 1a0a318

Browse files
committed
Update gps check
1 parent 61cccda commit 1a0a318

File tree

5 files changed

+43
-10
lines changed

5 files changed

+43
-10
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ apply plugin: 'kotlin-android'
44
apply plugin: 'kotlin-android-extensions'
55

66
group = 'com.kylecorry'
7-
version = '1.0.5'
7+
version = '1.0.6'
88

99
android {
1010
compileSdkVersion 30
1111

1212
defaultConfig {
1313
minSdkVersion 23
1414
targetSdkVersion 30
15-
versionCode 6
15+
versionCode 7
1616
versionName version
1717

1818
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

app/src/main/java/com/kylecorry/trailsensecore/domain/astronomy/AstronomyService.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ class AstronomyService : IAstronomyService {
8888
)
8989
}
9090

91+
override fun isSunUp(
92+
time: ZonedDateTime,
93+
location: Coordinate,
94+
withRefraction: Boolean
95+
): Boolean {
96+
return getSunAltitude(time, location, withRefraction) > 0
97+
}
98+
9199
override fun getMoonEvents(
92100
date: ZonedDateTime, location: Coordinate,
93101
withRefraction: Boolean
@@ -158,4 +166,12 @@ class AstronomyService : IAstronomyService {
158166
return Astro.getMoonPhase(date)
159167
}
160168

169+
override fun isMoonUp(
170+
time: ZonedDateTime,
171+
location: Coordinate,
172+
withRefraction: Boolean
173+
): Boolean {
174+
return getMoonAltitude(time, location, withRefraction) > 0
175+
}
176+
161177
}

app/src/main/java/com/kylecorry/trailsensecore/domain/astronomy/IAstronomyService.kt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ interface IAstronomyService {
3232
withRefraction: Boolean = false
3333
): ZonedDateTime?
3434

35-
fun isSunUp(time: ZonedDateTime, location: Coordinate, withRefraction: Boolean = false): Boolean {
36-
return getSunAltitude(time, location, withRefraction) > 0
37-
}
38-
35+
fun isSunUp(time: ZonedDateTime, location: Coordinate, withRefraction: Boolean = false): Boolean
3936

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

48-
fun isMoonUp(time: ZonedDateTime, location: Coordinate, withRefraction: Boolean = false): Boolean {
49-
return getMoonAltitude(time, location, withRefraction) > 0
50-
}
45+
fun isMoonUp(time: ZonedDateTime, location: Coordinate, withRefraction: Boolean = false): Boolean
5146

5247
}

app/src/main/java/com/kylecorry/trailsensecore/infrastructure/sensors/SensorChecker.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import android.content.Context
55
import android.content.pm.PackageManager
66
import android.hardware.Sensor
77
import android.hardware.SensorManager
8+
import android.location.LocationManager
89
import androidx.core.content.getSystemService
10+
import com.kylecorry.trailsensecore.infrastructure.system.PermissionUtils
911

1012
class SensorChecker(private val context: Context) {
1113

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

1820
fun hasGPS(): Boolean {
19-
return context.checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
21+
if (!PermissionUtils.isLocationEnabled(context)) {
22+
return false
23+
}
24+
25+
val lm = context.getSystemService<LocationManager>()
26+
try {
27+
return lm?.isProviderEnabled(LocationManager.GPS_PROVIDER) ?: false
28+
} catch (e: Exception) {
29+
// Do nothing
30+
}
31+
return false
2032
}
2133

2234
fun hasGravity(): Boolean {

app/src/main/java/com/kylecorry/trailsensecore/infrastructure/sensors/gps/SimpleLocationListener.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,14 @@ internal class SimpleLocationListener(private val onLocationChangedFn: (location
88
override fun onLocationChanged(location: Location) {
99
onLocationChangedFn.invoke(location)
1010
}
11+
12+
override fun onStatusChanged(provider: String?, status: Int, extras: Bundle?) {
13+
}
14+
15+
override fun onProviderDisabled(provider: String) {
16+
}
17+
18+
override fun onProviderEnabled(provider: String) {
19+
20+
}
1121
}

0 commit comments

Comments
 (0)