-
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.
Migrate from Geocod API to Android's Geocoder class
- Loading branch information
1 parent
a37adc5
commit 9205525
Showing
10 changed files
with
65 additions
and
139 deletions.
There are no files selected for viewing
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
11 changes: 0 additions & 11 deletions
11
app/src/main/java/com/abdurakhmanov/ridez/data/response/CurrentAddress.kt
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
app/src/main/java/com/abdurakhmanov/ridez/data/source/remote/GeocoderApiService.kt
This file was deleted.
Oops, something went wrong.
32 changes: 0 additions & 32 deletions
32
app/src/main/java/com/abdurakhmanov/ridez/di/NetworkModule.kt
This file was deleted.
Oops, something went wrong.
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
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
41 changes: 41 additions & 0 deletions
41
app/src/main/java/com/abdurakhmanov/ridez/utils/LocationExt.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,41 @@ | ||
package com.abdurakhmanov.ridez.utils | ||
|
||
import android.content.Context | ||
import android.location.Geocoder | ||
import android.location.LocationManager | ||
import android.os.Build | ||
import androidx.core.location.LocationManagerCompat | ||
|
||
/** | ||
* Checks whether user enabled the location or not. | ||
* | ||
* @return true if location is enabled or false if location is disabled | ||
*/ | ||
fun Context.isLocationEnabled(): Boolean { | ||
val locationManager = getSystemService(Context.LOCATION_SERVICE) as LocationManager | ||
return LocationManagerCompat.isLocationEnabled(locationManager) | ||
} | ||
|
||
/** | ||
* Gets current address of the user using latitude and longitude. | ||
* | ||
* @return user's current address | ||
*/ | ||
@Suppress("DEPRECATION") | ||
fun Geocoder.getAddress( | ||
latitude: Double, | ||
longitude: Double, | ||
address: (android.location.Address?) -> Unit | ||
) { | ||
|
||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { | ||
getFromLocation(latitude, longitude, 1) { address(it.firstOrNull()) } | ||
return | ||
} | ||
|
||
try { | ||
address(getFromLocation(latitude, longitude, 1)!!.firstOrNull()) | ||
} catch (e: Exception) { | ||
address(null) | ||
} | ||
} |
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