-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added #17 added to check location before to call getWeather
- Loading branch information
1 parent
13c51c4
commit 8eb0429
Showing
3 changed files
with
65 additions
and
31 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
app/src/main/java/com/architectcoders/openweather/CheckLocation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.architectcoders.openweather | ||
|
||
import android.location.LocationManager | ||
|
||
class CheckLocation(var locationManager: LocationManager) { | ||
|
||
fun checkLocation( continuation: (Boolean) -> Unit) { | ||
|
||
var gpsEnabled = false | ||
var networkEnabled = false | ||
|
||
try { | ||
gpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) | ||
} catch (ex: Exception) { | ||
} | ||
|
||
try { | ||
networkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER) | ||
} catch (ex: Exception) { | ||
} | ||
if (!gpsEnabled && !networkEnabled) { | ||
continuation(false) | ||
} else { | ||
continuation(true) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters