Search in sources :

Example 1 with NearbyPlacesInfo

use of fr.free.nrw.commons.nearby.NearbyController.NearbyPlacesInfo in project apps-android-commons by commons-app.

the class NearbyParentFragment method populatePlacesForAnotherLocation.

private void populatePlacesForAnotherLocation(final fr.free.nrw.commons.location.LatLng curlatLng, final fr.free.nrw.commons.location.LatLng searchLatLng, @Nullable final String customQuery) {
    final Observable<NearbyPlacesInfo> nearbyPlacesInfoObservable = Observable.fromCallable(() -> nearbyController.loadAttractionsFromLocation(curlatLng, searchLatLng, false, true, Utils.isMonumentsEnabled(new Date()), customQuery));
    compositeDisposable.add(nearbyPlacesInfoObservable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(nearbyPlacesInfo -> {
        if (nearbyPlacesInfo.placeList == null || nearbyPlacesInfo.placeList.isEmpty()) {
            showErrorMessage(getString(R.string.no_nearby_places_around));
        } else {
            // Updating last searched location
            applicationKvStore.putString("LastLocation", searchLatLng.getLatitude() + "," + searchLatLng.getLongitude());
            updateMapMarkers(nearbyPlacesInfo, false);
            lastFocusLocation = searchLatLng;
        }
    }, throwable -> {
        Timber.e(throwable);
        showErrorMessage(getString(R.string.error_fetching_nearby_places) + throwable.getLocalizedMessage());
        setProgressBarVisibility(false);
        presenter.lockUnlockNearby(false);
        setFilterState();
    }));
}
Also used : DividerItemDecoration(androidx.recyclerview.widget.DividerItemDecoration) Chip(com.google.android.material.chip.Chip) Bundle(android.os.Bundle) ProgressBar(android.widget.ProgressBar) NonNull(androidx.annotation.NonNull) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) BookmarkLocationsDao(fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao) MapView(com.mapbox.mapboxsdk.maps.MapView) Marker(com.mapbox.mapboxsdk.annotations.Marker) VectorDrawableCompat(androidx.vectordrawable.graphics.drawable.VectorDrawableCompat) OnClick(butterknife.OnClick) CommonsApplication(fr.free.nrw.commons.CommonsApplication) Manifest(android.Manifest) Utils(fr.free.nrw.commons.Utils) Log(android.util.Log) RxSearchView(com.jakewharton.rxbinding3.appcompat.RxSearchView) IntentFilter(android.content.IntentFilter) SearchView(androidx.appcompat.widget.SearchView) LocationServiceManager(fr.free.nrw.commons.location.LocationServiceManager) LayoutUtils(fr.free.nrw.commons.utils.LayoutUtils) Unit(kotlin.Unit) Nullable(androidx.annotation.Nullable) SystemThemeUtils(fr.free.nrw.commons.utils.SystemThemeUtils) UiUtils(fr.free.nrw.commons.utils.UiUtils) LOCATION_SLIGHTLY_CHANGED(fr.free.nrw.commons.location.LocationServiceManager.LocationChangeType.LOCATION_SLIGHTLY_CHANGED) Html(android.text.Html) LOCATION_SIGNIFICANTLY_CHANGED(fr.free.nrw.commons.location.LocationServiceManager.LocationChangeType.LOCATION_SIGNIFICANTLY_CHANGED) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) LatLngBounds(com.mapbox.mapboxsdk.geometry.LatLngBounds) CommonsDaggerSupportFragment(fr.free.nrw.commons.di.CommonsDaggerSupportFragment) Place(fr.free.nrw.commons.nearby.Place) ButterKnife(butterknife.ButterKnife) BottomSheetBehavior(com.google.android.material.bottomsheet.BottomSheetBehavior) OnMenuItemClickListener(android.view.MenuItem.OnMenuItemClickListener) ChipGroup(com.google.android.material.chip.ChipGroup) NearbyParentFragmentPresenter(fr.free.nrw.commons.nearby.presenter.NearbyParentFragmentPresenter) Callback(fr.free.nrw.commons.nearby.fragments.AdvanceQueryFragment.Callback) ArrayList(java.util.ArrayList) CameraUpdateFactory(com.mapbox.mapboxsdk.camera.CameraUpdateFactory) RxView(com.jakewharton.rxbinding2.view.RxView) MenuInflater(android.view.MenuInflater) Toast(android.widget.Toast) Menu(android.view.Menu) CameraPosition(com.mapbox.mapboxsdk.camera.CameraPosition) Settings(android.provider.Settings) Observable(io.reactivex.Observable) Named(javax.inject.Named) MapboxMap(com.mapbox.mapboxsdk.maps.MapboxMap) LocationUtils(fr.free.nrw.commons.utils.LocationUtils) ScaleBarOptions(com.mapbox.pluginscalebar.ScaleBarOptions) IOException(java.io.IOException) Gravity(android.view.Gravity) NearbyPlacesInfo(fr.free.nrw.commons.nearby.NearbyController.NearbyPlacesInfo) Configuration(android.content.res.Configuration) NetworkUtils(fr.free.nrw.commons.utils.NetworkUtils) NearbyMarker(fr.free.nrw.commons.nearby.NearbyMarker) LinearLayout(android.widget.LinearLayout) MainActivity(fr.free.nrw.commons.contributions.MainActivity) LengthUtils.formatDistanceBetween(fr.free.nrw.commons.utils.LengthUtils.formatDistanceBetween) UiSettings(com.mapbox.mapboxsdk.maps.UiSettings) PackageManager(android.content.pm.PackageManager) AppCompatImageView(androidx.appcompat.widget.AppCompatImageView) Date(java.util.Date) R(fr.free.nrw.commons.R) LinkMovementMethod(android.text.method.LinkMovementMethod) DrawableRes(androidx.annotation.DrawableRes) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) BindView(butterknife.BindView) ScaleBarPlugin(com.mapbox.pluginscalebar.ScaleBarPlugin) MarkerOptions(com.mapbox.mapboxsdk.annotations.MarkerOptions) ActiveFragment(fr.free.nrw.commons.contributions.MainActivity.ActiveFragment) FloatingActionButton(com.google.android.material.floatingactionbutton.FloatingActionButton) View(android.view.View) Button(android.widget.Button) Schedulers(io.reactivex.schedulers.Schedulers) Animation(android.view.animation.Animation) RecyclerView(androidx.recyclerview.widget.RecyclerView) Label(fr.free.nrw.commons.nearby.Label) JsonKvStore(fr.free.nrw.commons.kvstore.JsonKvStore) BroadcastReceiver(android.content.BroadcastReceiver) AppCompatButton(androidx.appcompat.widget.AppCompatButton) ViewGroup(android.view.ViewGroup) CheckBoxTriStates(fr.free.nrw.commons.nearby.CheckBoxTriStates) Timber(timber.log.Timber) CUSTOM_QUERY(fr.free.nrw.commons.location.LocationServiceManager.LocationChangeType.CUSTOM_QUERY) PolygonOptions(com.mapbox.mapboxsdk.annotations.PolygonOptions) FileUtils(fr.free.nrw.commons.upload.FileUtils) List(java.util.List) TextView(android.widget.TextView) NearbyBaseMarker(fr.free.nrw.commons.nearby.NearbyBaseMarker) Style(com.mapbox.mapboxsdk.maps.Style) RelativeLayout(android.widget.RelativeLayout) PermissionUtils(fr.free.nrw.commons.utils.PermissionUtils) NotNull(org.jetbrains.annotations.NotNull) LocationManager(android.location.LocationManager) Snackbar(com.google.android.material.snackbar.Snackbar) NearbyParentFragmentContract(fr.free.nrw.commons.nearby.contract.NearbyParentFragmentContract) AppCompatTextView(androidx.appcompat.widget.AppCompatTextView) DialogUtil(fr.free.nrw.commons.utils.DialogUtil) Context(android.content.Context) IconFactory(com.mapbox.mapboxsdk.annotations.IconFactory) NearbyFilterState(fr.free.nrw.commons.nearby.NearbyFilterState) AlertDialog(androidx.appcompat.app.AlertDialog) WikidataEditListener(fr.free.nrw.commons.wikidata.WikidataEditListener) Intent(android.content.Intent) ExecutorUtils(fr.free.nrw.commons.utils.ExecutorUtils) ViewUtil(fr.free.nrw.commons.utils.ViewUtil) MAP_UPDATED(fr.free.nrw.commons.location.LocationServiceManager.LocationChangeType.MAP_UPDATED) ContributionController(fr.free.nrw.commons.contributions.ContributionController) MenuItem(android.view.MenuItem) AnimationUtils(android.view.animation.AnimationUtils) Inject(javax.inject.Inject) SuppressLint(android.annotation.SuppressLint) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) LoginActivity(fr.free.nrw.commons.auth.LoginActivity) LocationUpdateListener(fr.free.nrw.commons.location.LocationUpdateListener) MotionEvent(android.view.MotionEvent) Icon(com.mapbox.mapboxsdk.annotations.Icon) MarkerPlaceGroup(fr.free.nrw.commons.nearby.MarkerPlaceGroup) Iterator(java.util.Iterator) LayoutInflater(android.view.LayoutInflater) TimeUnit(java.util.concurrent.TimeUnit) Bitmap(android.graphics.Bitmap) NearbyFilterSearchRecyclerViewAdapter(fr.free.nrw.commons.nearby.NearbyFilterSearchRecyclerViewAdapter) NearbyController(fr.free.nrw.commons.nearby.NearbyController) Polygon(com.mapbox.mapboxsdk.annotations.Polygon) NearbyFABUtils(fr.free.nrw.commons.utils.NearbyFABUtils) PLACE_OBJECT(fr.free.nrw.commons.wikidata.WikidataConstants.PLACE_OBJECT) NearbyPlacesInfo(fr.free.nrw.commons.nearby.NearbyController.NearbyPlacesInfo) Date(java.util.Date)

Example 2 with NearbyPlacesInfo

use of fr.free.nrw.commons.nearby.NearbyController.NearbyPlacesInfo in project apps-android-commons by commons-app.

the class NearbyParentFragment method populatePlacesForCurrentLocation.

private void populatePlacesForCurrentLocation(final fr.free.nrw.commons.location.LatLng curlatLng, final fr.free.nrw.commons.location.LatLng searchLatLng, @Nullable final String customQuery) {
    final Observable<NearbyPlacesInfo> nearbyPlacesInfoObservable = Observable.fromCallable(() -> nearbyController.loadAttractionsFromLocation(curlatLng, searchLatLng, false, true, Utils.isMonumentsEnabled(new Date()), customQuery));
    compositeDisposable.add(nearbyPlacesInfoObservable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(nearbyPlacesInfo -> {
        if (nearbyPlacesInfo.placeList == null || nearbyPlacesInfo.placeList.isEmpty()) {
            showErrorMessage(getString(R.string.no_nearby_places_around));
        } else {
            updateMapMarkers(nearbyPlacesInfo, true);
            lastFocusLocation = searchLatLng;
        }
    }, throwable -> {
        Timber.d(throwable);
        showErrorMessage(getString(R.string.error_fetching_nearby_places) + throwable.getLocalizedMessage());
        setProgressBarVisibility(false);
        presenter.lockUnlockNearby(false);
        setFilterState();
    }));
}
Also used : DividerItemDecoration(androidx.recyclerview.widget.DividerItemDecoration) Chip(com.google.android.material.chip.Chip) Bundle(android.os.Bundle) ProgressBar(android.widget.ProgressBar) NonNull(androidx.annotation.NonNull) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) BookmarkLocationsDao(fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao) MapView(com.mapbox.mapboxsdk.maps.MapView) Marker(com.mapbox.mapboxsdk.annotations.Marker) VectorDrawableCompat(androidx.vectordrawable.graphics.drawable.VectorDrawableCompat) OnClick(butterknife.OnClick) CommonsApplication(fr.free.nrw.commons.CommonsApplication) Manifest(android.Manifest) Utils(fr.free.nrw.commons.Utils) Log(android.util.Log) RxSearchView(com.jakewharton.rxbinding3.appcompat.RxSearchView) IntentFilter(android.content.IntentFilter) SearchView(androidx.appcompat.widget.SearchView) LocationServiceManager(fr.free.nrw.commons.location.LocationServiceManager) LayoutUtils(fr.free.nrw.commons.utils.LayoutUtils) Unit(kotlin.Unit) Nullable(androidx.annotation.Nullable) SystemThemeUtils(fr.free.nrw.commons.utils.SystemThemeUtils) UiUtils(fr.free.nrw.commons.utils.UiUtils) LOCATION_SLIGHTLY_CHANGED(fr.free.nrw.commons.location.LocationServiceManager.LocationChangeType.LOCATION_SLIGHTLY_CHANGED) Html(android.text.Html) LOCATION_SIGNIFICANTLY_CHANGED(fr.free.nrw.commons.location.LocationServiceManager.LocationChangeType.LOCATION_SIGNIFICANTLY_CHANGED) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) LatLngBounds(com.mapbox.mapboxsdk.geometry.LatLngBounds) CommonsDaggerSupportFragment(fr.free.nrw.commons.di.CommonsDaggerSupportFragment) Place(fr.free.nrw.commons.nearby.Place) ButterKnife(butterknife.ButterKnife) BottomSheetBehavior(com.google.android.material.bottomsheet.BottomSheetBehavior) OnMenuItemClickListener(android.view.MenuItem.OnMenuItemClickListener) ChipGroup(com.google.android.material.chip.ChipGroup) NearbyParentFragmentPresenter(fr.free.nrw.commons.nearby.presenter.NearbyParentFragmentPresenter) Callback(fr.free.nrw.commons.nearby.fragments.AdvanceQueryFragment.Callback) ArrayList(java.util.ArrayList) CameraUpdateFactory(com.mapbox.mapboxsdk.camera.CameraUpdateFactory) RxView(com.jakewharton.rxbinding2.view.RxView) MenuInflater(android.view.MenuInflater) Toast(android.widget.Toast) Menu(android.view.Menu) CameraPosition(com.mapbox.mapboxsdk.camera.CameraPosition) Settings(android.provider.Settings) Observable(io.reactivex.Observable) Named(javax.inject.Named) MapboxMap(com.mapbox.mapboxsdk.maps.MapboxMap) LocationUtils(fr.free.nrw.commons.utils.LocationUtils) ScaleBarOptions(com.mapbox.pluginscalebar.ScaleBarOptions) IOException(java.io.IOException) Gravity(android.view.Gravity) NearbyPlacesInfo(fr.free.nrw.commons.nearby.NearbyController.NearbyPlacesInfo) Configuration(android.content.res.Configuration) NetworkUtils(fr.free.nrw.commons.utils.NetworkUtils) NearbyMarker(fr.free.nrw.commons.nearby.NearbyMarker) LinearLayout(android.widget.LinearLayout) MainActivity(fr.free.nrw.commons.contributions.MainActivity) LengthUtils.formatDistanceBetween(fr.free.nrw.commons.utils.LengthUtils.formatDistanceBetween) UiSettings(com.mapbox.mapboxsdk.maps.UiSettings) PackageManager(android.content.pm.PackageManager) AppCompatImageView(androidx.appcompat.widget.AppCompatImageView) Date(java.util.Date) R(fr.free.nrw.commons.R) LinkMovementMethod(android.text.method.LinkMovementMethod) DrawableRes(androidx.annotation.DrawableRes) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) BindView(butterknife.BindView) ScaleBarPlugin(com.mapbox.pluginscalebar.ScaleBarPlugin) MarkerOptions(com.mapbox.mapboxsdk.annotations.MarkerOptions) ActiveFragment(fr.free.nrw.commons.contributions.MainActivity.ActiveFragment) FloatingActionButton(com.google.android.material.floatingactionbutton.FloatingActionButton) View(android.view.View) Button(android.widget.Button) Schedulers(io.reactivex.schedulers.Schedulers) Animation(android.view.animation.Animation) RecyclerView(androidx.recyclerview.widget.RecyclerView) Label(fr.free.nrw.commons.nearby.Label) JsonKvStore(fr.free.nrw.commons.kvstore.JsonKvStore) BroadcastReceiver(android.content.BroadcastReceiver) AppCompatButton(androidx.appcompat.widget.AppCompatButton) ViewGroup(android.view.ViewGroup) CheckBoxTriStates(fr.free.nrw.commons.nearby.CheckBoxTriStates) Timber(timber.log.Timber) CUSTOM_QUERY(fr.free.nrw.commons.location.LocationServiceManager.LocationChangeType.CUSTOM_QUERY) PolygonOptions(com.mapbox.mapboxsdk.annotations.PolygonOptions) FileUtils(fr.free.nrw.commons.upload.FileUtils) List(java.util.List) TextView(android.widget.TextView) NearbyBaseMarker(fr.free.nrw.commons.nearby.NearbyBaseMarker) Style(com.mapbox.mapboxsdk.maps.Style) RelativeLayout(android.widget.RelativeLayout) PermissionUtils(fr.free.nrw.commons.utils.PermissionUtils) NotNull(org.jetbrains.annotations.NotNull) LocationManager(android.location.LocationManager) Snackbar(com.google.android.material.snackbar.Snackbar) NearbyParentFragmentContract(fr.free.nrw.commons.nearby.contract.NearbyParentFragmentContract) AppCompatTextView(androidx.appcompat.widget.AppCompatTextView) DialogUtil(fr.free.nrw.commons.utils.DialogUtil) Context(android.content.Context) IconFactory(com.mapbox.mapboxsdk.annotations.IconFactory) NearbyFilterState(fr.free.nrw.commons.nearby.NearbyFilterState) AlertDialog(androidx.appcompat.app.AlertDialog) WikidataEditListener(fr.free.nrw.commons.wikidata.WikidataEditListener) Intent(android.content.Intent) ExecutorUtils(fr.free.nrw.commons.utils.ExecutorUtils) ViewUtil(fr.free.nrw.commons.utils.ViewUtil) MAP_UPDATED(fr.free.nrw.commons.location.LocationServiceManager.LocationChangeType.MAP_UPDATED) ContributionController(fr.free.nrw.commons.contributions.ContributionController) MenuItem(android.view.MenuItem) AnimationUtils(android.view.animation.AnimationUtils) Inject(javax.inject.Inject) SuppressLint(android.annotation.SuppressLint) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) LoginActivity(fr.free.nrw.commons.auth.LoginActivity) LocationUpdateListener(fr.free.nrw.commons.location.LocationUpdateListener) MotionEvent(android.view.MotionEvent) Icon(com.mapbox.mapboxsdk.annotations.Icon) MarkerPlaceGroup(fr.free.nrw.commons.nearby.MarkerPlaceGroup) Iterator(java.util.Iterator) LayoutInflater(android.view.LayoutInflater) TimeUnit(java.util.concurrent.TimeUnit) Bitmap(android.graphics.Bitmap) NearbyFilterSearchRecyclerViewAdapter(fr.free.nrw.commons.nearby.NearbyFilterSearchRecyclerViewAdapter) NearbyController(fr.free.nrw.commons.nearby.NearbyController) Polygon(com.mapbox.mapboxsdk.annotations.Polygon) NearbyFABUtils(fr.free.nrw.commons.utils.NearbyFABUtils) PLACE_OBJECT(fr.free.nrw.commons.wikidata.WikidataConstants.PLACE_OBJECT) NearbyPlacesInfo(fr.free.nrw.commons.nearby.NearbyController.NearbyPlacesInfo) Date(java.util.Date)

Aggregations

Manifest (android.Manifest)2 SuppressLint (android.annotation.SuppressLint)2 BroadcastReceiver (android.content.BroadcastReceiver)2 Context (android.content.Context)2 Intent (android.content.Intent)2 IntentFilter (android.content.IntentFilter)2 PackageManager (android.content.pm.PackageManager)2 Configuration (android.content.res.Configuration)2 Bitmap (android.graphics.Bitmap)2 LocationManager (android.location.LocationManager)2 Uri (android.net.Uri)2 Bundle (android.os.Bundle)2 Settings (android.provider.Settings)2 Html (android.text.Html)2 LinkMovementMethod (android.text.method.LinkMovementMethod)2 Log (android.util.Log)2 Gravity (android.view.Gravity)2 LayoutInflater (android.view.LayoutInflater)2 Menu (android.view.Menu)2 MenuInflater (android.view.MenuInflater)2