forked from fossasia/open-event-attendee-android
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement location feature in f-droid (fossasia#2006)
- Loading branch information
1 parent
7e3ca1e
commit dc9f661
Showing
10 changed files
with
91 additions
and
151 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
50 changes: 48 additions & 2 deletions
50
app/src/fdroid/java/org/fossasia/openevent/general/search/location/LocationServiceImpl.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 |
---|---|---|
@@ -1,11 +1,57 @@ | ||
package org.fossasia.openevent.general.search.location | ||
|
||
import android.annotation.SuppressLint | ||
import android.content.Context | ||
import android.location.Geocoder | ||
import android.location.Location | ||
import android.location.LocationListener | ||
import android.location.LocationManager | ||
import android.os.Bundle | ||
import io.reactivex.Single | ||
import java.lang.IllegalArgumentException | ||
import java.util.Locale | ||
|
||
class LocationServiceImpl(context: Context) : LocationService { | ||
class LocationServiceImpl(private val context: Context) : LocationService { | ||
|
||
@SuppressLint("MissingPermission") | ||
override fun getAdministrativeArea(): Single<String> { | ||
throw IllegalStateException("Attempt to use location functionality in F-Droid flavor") | ||
val locationManager = context.getSystemService(Context.LOCATION_SERVICE) as? LocationManager | ||
?: return Single.error(IllegalStateException()) | ||
val geoCoder = Geocoder(context, Locale.getDefault()) | ||
|
||
return Single.create { emitter -> | ||
try { | ||
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0f, | ||
object : LocationListener { | ||
override fun onLocationChanged(location: Location?) { | ||
if (location == null) { | ||
emitter.onError(java.lang.IllegalStateException()) | ||
return | ||
} | ||
val addresses = geoCoder.getFromLocation(location.latitude, location.longitude, 1) | ||
try { | ||
val adminArea = addresses[0].adminArea | ||
emitter.onSuccess(adminArea) | ||
} catch (e: IllegalArgumentException) { | ||
emitter.onError(e) | ||
} | ||
} | ||
|
||
override fun onStatusChanged(provider: String?, status: Int, extras: Bundle?) { | ||
// To change body of created functions use File | Settings | File Templates. | ||
} | ||
|
||
override fun onProviderEnabled(provider: String?) { | ||
// To change body of created functions use File | Settings | File Templates. | ||
} | ||
|
||
override fun onProviderDisabled(provider: String?) { | ||
// To change body of created functions use File | Settings | File Templates. | ||
} | ||
}) | ||
} catch (e: SecurityException) { | ||
emitter.onError(e) | ||
} | ||
} | ||
} | ||
} |
39 changes: 0 additions & 39 deletions
39
app/src/fdroid/java/org/fossasia/openevent/general/welcome/WelcomeFragment.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
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 was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
app/src/playStore/java/org/fossasia/openevent/general/di/FlavorSpecificModules.kt
This file was deleted.
Oops, something went wrong.
58 changes: 0 additions & 58 deletions
58
app/src/playStore/java/org/fossasia/openevent/general/welcome/WelcomeViewModel.kt
This file was deleted.
Oops, something went wrong.