-
Notifications
You must be signed in to change notification settings - Fork 553
feat: Implement location feature in f-droid build #2008
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No use of fine AFAIK, or is there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here
LocationManager.NETWORK_PROVIDER
is used so fine location is required.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to https://developer.android.com/guide/topics/location/strategies.html