Skip to content

Commit df15e30

Browse files
committed
Call serch with and without query from the same spot
1 parent b8db9ad commit df15e30

13 files changed

+95
-566
lines changed

app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapController.java

+5-43
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,16 @@
4040
public class ExploreMapController extends MapController {
4141
private static final int MAX_RESULTS = 1000;
4242
private final ExplorePlaces explorePlaces;
43-
public static LatLng latestSearchLocation; // Can be current and camera target on search this area button is used
44-
public static double latestSearchRadius = 10.0; // Any last search radius except closest result search
45-
public static double farthestDistance;
43+
public LatLng latestSearchLocation; // Can be current and camera target on search this area button is used
44+
public double latestSearchRadius = 10.0; // Any last search radius except closest result search
4645

4746

4847
@Inject
4948
public ExploreMapController(ExplorePlaces explorePlaces) {
5049
this.explorePlaces = explorePlaces;
5150
}
5251

53-
public ExplorePlacesInfo loadAttractionsFromLocation(LatLng curLatLng, LatLng searchLatLng, boolean checkingAroundCurrentLocation) {
52+
public ExplorePlacesInfo loadAttractionsFromLocation(LatLng curLatLng, LatLng searchLatLng, boolean checkingAroundCurrentLocation, boolean isFromSearchActivity, String query) {
5453

5554
// TODO: check nearbyPlacesInfo in NearbyController for search this area logic
5655

@@ -63,8 +62,7 @@ public ExplorePlacesInfo loadAttractionsFromLocation(LatLng curLatLng, LatLng se
6362
try {
6463
explorePlacesInfo.curLatLng = curLatLng;
6564
latestSearchLocation = searchLatLng;
66-
List<Media> mediaList = explorePlaces.callCommonsQuery(searchLatLng, 30);
67-
65+
List<Media> mediaList = explorePlaces.callCommonsQuery(curLatLng, 30, isFromSearchActivity, query);
6866
LatLng[] boundaryCoordinates = {mediaList.get(0).getCoordinates(), // south
6967
mediaList.get(0).getCoordinates(), // north
7068
mediaList.get(0).getCoordinates(), // west
@@ -98,15 +96,11 @@ public ExplorePlacesInfo loadAttractionsFromLocation(LatLng curLatLng, LatLng se
9896
}
9997
);
10098
}
101-
102-
Log.d("nesli2","mediaList" + mediaList);
10399
explorePlacesInfo.explorePlaceList = mediaToExplorePlace(mediaList);
104100
explorePlacesInfo.boundaryCoordinates = boundaryCoordinates;
105101
} catch (Exception e) {
106102
e.printStackTrace();
107-
Log.d("nesli2","error happened"+e.toString());
108103
}
109-
//Log.d("nesli2","nearby places info" + explorePlacesInfo.explorePlaceList.get(0));
110104
return explorePlacesInfo;
111105
}
112106

@@ -165,42 +159,10 @@ public static List<NearbyBaseMarker> loadAttractionsFromLocationToBaseMarkerOpti
165159
explorePlace.location.getLatitude(),
166160
explorePlace.location.getLongitude()));
167161
nearbyBaseMarker.place(explorePlace);
168-
/* Help needed, Madhur another point that would be nice to have help is here where I want to create marker icons from thumbnails of places.
169-
I guess a library like Glide should be used but tried once and couldn't make it work yet. I assume something like that:
170-
171-
Drawable drawable = Glide.with(context).load(explorePlace.thumb).thumbnail(0.3f).submit().get();
172-
nearbyBaseMarker.setIcon(IconFactory.getInstance(context).fromBitmap(UiUtils.drawableToBitmap(drawable)));
173-
174-
175-
OR
176-
177-
Glide.with(context).asBitmap().load(explorePlace.thumb).into(new CustomTarget<Bitmap>() {
178-
@Override
179-
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
180-
//imageView.setImageBitmap(resource);
181-
//nearbyBaseMarker.icon(IconFactory.getInstance(context)
182-
// .fromBitmap(resource));
183-
nearbyBaseMarker.setIcon(IconFactory.getInstance(context)
184-
.fromBitmap(resource));
185-
baseMarkerOptions.add(nearbyBaseMarker);
186-
}
187-
@Override
188-
public void onLoadCleared(@Nullable Drawable placeholder) {
189-
}
190-
});*/
162+
// TODO Glide and thumbnails here
191163

192164
nearbyBaseMarker.icon(IconFactory.getInstance(context).fromBitmap(UiUtils.getBitmap(vectorDrawableGreen)));
193165
baseMarkerOptions.add(nearbyBaseMarker);
194-
195-
/*if (!explorePlace.pic.trim().isEmpty()) {
196-
if (iconGreen != null) {
197-
nearbyBaseMarker.icon(IconFactory.getInstance(context)
198-
.fromBitmap(thumnail));
199-
}
200-
}else {
201-
nearbyBaseMarker.icon(IconFactory.getInstance(context)
202-
.fromBitmap(thumnail));
203-
}*/
204166
}
205167
}
206168

app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapFragment.java

+13-82
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,12 @@
1313
import android.os.Bundle;
1414
import android.util.Log;
1515
import android.view.Gravity;
16-
import android.view.LayoutInflater;
1716
import android.view.MotionEvent;
1817
import android.view.View;
19-
import android.view.ViewGroup;
20-
import android.widget.ProgressBar;
2118
import android.widget.Toast;
2219
import androidx.annotation.NonNull;
2320
import androidx.annotation.Nullable;
24-
import butterknife.BindView;
25-
import butterknife.ButterKnife;
2621
import com.google.android.material.bottomsheet.BottomSheetBehavior;
27-
import com.google.android.material.floatingactionbutton.FloatingActionButton;
2822
import com.google.android.material.snackbar.Snackbar;
2923
import com.mapbox.mapboxsdk.annotations.Icon;
3024
import com.mapbox.mapboxsdk.annotations.IconFactory;
@@ -36,24 +30,17 @@
3630
import com.mapbox.mapboxsdk.camera.CameraUpdate;
3731
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
3832
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
39-
import com.mapbox.mapboxsdk.maps.MapView;
4033
import com.mapbox.mapboxsdk.maps.MapboxMap;
4134
import com.mapbox.mapboxsdk.maps.Style;
4235
import com.mapbox.mapboxsdk.maps.UiSettings;
4336
import com.mapbox.pluginscalebar.ScaleBarOptions;
4437
import com.mapbox.pluginscalebar.ScaleBarPlugin;
4538
import fr.free.nrw.commons.MapController;
46-
import fr.free.nrw.commons.Media;
4739
import fr.free.nrw.commons.R;
48-
import fr.free.nrw.commons.Utils;
4940
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao;
5041
import fr.free.nrw.commons.category.CategoryImagesCallback;
51-
import fr.free.nrw.commons.contributions.MainActivity;
52-
import fr.free.nrw.commons.contributions.MainActivity.ActiveFragment;
53-
import fr.free.nrw.commons.di.CommonsApplicationModule;
5442
import fr.free.nrw.commons.explore.SearchActivity;
5543
import fr.free.nrw.commons.explore.paging.LiveDataConverter;
56-
import fr.free.nrw.commons.explore.paging.PagingContract.Presenter;
5744
import fr.free.nrw.commons.kvstore.JsonKvStore;
5845
import fr.free.nrw.commons.location.LatLng;
5946
import fr.free.nrw.commons.location.LocationServiceManager;
@@ -70,11 +57,8 @@
7057
import fr.free.nrw.commons.utils.UiUtils;
7158
import fr.free.nrw.commons.utils.ViewUtil;
7259
import io.reactivex.Observable;
73-
import io.reactivex.Scheduler;
7460
import io.reactivex.android.schedulers.AndroidSchedulers;
7561
import io.reactivex.schedulers.Schedulers;
76-
import java.util.ArrayList;
77-
import java.util.Date;
7862
import java.util.List;
7963
import javax.inject.Inject;
8064
import javax.inject.Named;
@@ -105,12 +89,6 @@ public class ExploreMapFragment extends PageableMapFragment
10589
private ExploreFragmentInstanceReadyCallback exploreFragmentInstanceReadyCallback;
10690
IntentFilter intentFilter = new IntentFilter(MapUtils.NETWORK_INTENT_ACTION);
10791

108-
@Inject
109-
ExploreMapMediaDataSource dataSourceFactory;
110-
@Inject
111-
ExploreMapMediaPresenter mediaPresenter;
112-
// Help wanted: Hey Madhur, one help need is binding these two variable above
113-
11492
@Inject
11593
LiveDataConverter liveDataConverter;
11694
@Inject
@@ -119,8 +97,6 @@ public class ExploreMapFragment extends PageableMapFragment
11997
LocationServiceManager locationManager;
12098
@Inject
12199
ExploreMapController exploreMapController;
122-
@Inject
123-
ExploreWithQueryMapController exploreWithQueryMapController;
124100
@Inject @Named("default_preferences")
125101
JsonKvStore applicationKvStore;
126102
@Inject
@@ -129,20 +105,8 @@ public class ExploreMapFragment extends PageableMapFragment
129105
SystemThemeUtils systemThemeUtils;
130106

131107
private boolean isFromSearchActivity;
132-
133-
/*@BindView(R.id.map_view)
134-
MapView mapView;
135-
@BindView(R.id.bottom_sheet_details)
136-
View bottomSheetDetails;
137-
@BindView(R.id.map_progress_bar)
138-
ProgressBar progressBar;
139-
@BindView(R.id.fab_recenter)
140-
FloatingActionButton fabRecenter;*/
141-
142-
143-
//private View view;
144108
private ExploreMapPresenter presenter;
145-
private String customQuery;
109+
private String query = "";
146110

147111

148112
@NonNull
@@ -157,32 +121,15 @@ protected int getLayoutResource() {
157121
return R.layout.fragment_search_map_paginated;
158122
}
159123

160-
//@Override
161-
//public View onCreateView(@NonNull final LayoutInflater inflater, final ViewGroup container,
162-
//final Bundle savedInstanceState) {
163-
//super.onCreateView(inflater, container, savedInstanceState);
164-
//view = inflater.inflate(R.layout.fragment_explore_map, container, false);
165-
//ButterKnife.bind(this, getView());
166-
167-
168-
// Inflate the layout for this fragmentz
169-
//return getView();
170-
//}
171-
172-
173124
@Override
174125
public void onCreate(@Nullable final Bundle savedInstanceState) {
175126
super.onCreate(savedInstanceState);
176-
//dataSourceFactory = new ExploreMapMediaDataSource(liveDataConverter, mediaClient, isFromSearchActivity);
177-
//mediaPresenter = new ExploreMapMediaPresenterIml(scheduler, dataSourceFactory,isFromSearchActivity);
178127
}
179128

129+
180130
@Override
181131
public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) {
182132
super.onViewCreated(view, savedInstanceState);
183-
/*if (savedInstanceState != null) {
184-
onQueryUpdated(savedInstanceState.getString("placeName") + "map query");
185-
}*/
186133

187134
if (getActivity() instanceof SearchActivity) {
188135
isFromSearchActivity = true;
@@ -256,6 +203,11 @@ public void onResume() {
256203
}
257204
}
258205

206+
public void onQueryUpdated(String query) {
207+
this.query = query;
208+
performMapReadyActions();
209+
}
210+
259211
private void startTheMap() {
260212
mapView.onStart();
261213
performMapReadyActions();
@@ -270,7 +222,7 @@ private void startMapWithoutPermission() {
270222
if (mapBox != null) {
271223
addOnCameraMoveListener();
272224
}
273-
presenter.onMapReady();
225+
presenter.onMapReady(isFromSearchActivity, exploreMapController, query);
274226
// TODO nesli removeCurrentLocationMarker();
275227
}
276228

@@ -351,10 +303,8 @@ public boolean isNetworkConnectionEstablished() {
351303
@Override
352304
public void populatePlaces(LatLng curlatLng) {
353305
if (curlatLng.equals(lastFocusLocation) || lastFocusLocation == null || recenterToUserLocation) { // Means we are checking around current location
354-
Log.d("nesli2","populate places populatePlacesForCurrentLocation called");
355306
populatePlacesForCurrentLocation(lastKnownLocation, curlatLng);
356307
} else {
357-
Log.d("nesli2","populate places populatePlacesForAnotherLocation called");
358308
populatePlacesForAnotherLocation(lastKnownLocation, curlatLng);
359309
}
360310
if(recenterToUserLocation) {
@@ -365,17 +315,7 @@ public void populatePlaces(LatLng curlatLng) {
365315
private void populatePlacesForCurrentLocation(final fr.free.nrw.commons.location.LatLng curlatLng,
366316
final fr.free.nrw.commons.location.LatLng searchLatLng){
367317
final Observable<MapController.ExplorePlacesInfo> nearbyPlacesInfoObservable;
368-
if (!isFromSearchActivity) {
369-
nearbyPlacesInfoObservable = Observable
370-
.fromCallable(() -> exploreMapController
371-
.loadAttractionsFromLocation(curlatLng, searchLatLng,true));
372-
373-
} else {
374-
//Log.d("nesli3","presenters data source is:"+getPagedListAdapter().getCurrentList().snapshot());
375-
nearbyPlacesInfoObservable = Observable
376-
.fromCallable(() -> exploreWithQueryMapController
377-
.loadAttractionsFromLocation(curlatLng, searchLatLng,true));
378-
}
318+
nearbyPlacesInfoObservable = presenter.loadAttractionsFromLocation(curlatLng, searchLatLng, true, isFromSearchActivity, query);
379319

380320
compositeDisposable.add(nearbyPlacesInfoObservable
381321
.subscribeOn(Schedulers.io())
@@ -397,8 +337,8 @@ private void populatePlacesForAnotherLocation(final fr.free.nrw.commons.location
397337

398338
final Observable<MapController.ExplorePlacesInfo> nearbyPlacesInfoObservable = Observable
399339
.fromCallable(() -> exploreMapController
400-
.loadAttractionsFromLocation(curlatLng, searchLatLng,false));
401-
// TODO: check loadAttractionsromLocation with query parameter
340+
.loadAttractionsFromLocation(curlatLng, searchLatLng,false, isFromSearchActivity, query));
341+
// TODO: nesli do this over the presenter
402342

403343
compositeDisposable.add(nearbyPlacesInfoObservable
404344
.subscribeOn(Schedulers.io())
@@ -421,7 +361,6 @@ private void populatePlacesForAnotherLocation(final fr.free.nrw.commons.location
421361
* @param explorePlacesInfo This variable has place list information and distances.
422362
*/
423363
private void updateMapMarkers(final MapController.ExplorePlacesInfo explorePlacesInfo, final boolean shouldUpdateSelectedMarker) {
424-
Log.d("nesli2","updateMapMarkers1");
425364
presenter.updateMapMarkers(explorePlacesInfo, selectedMarker,shouldUpdateSelectedMarker);
426365
}
427366

@@ -464,7 +403,7 @@ else if(locationManager.isGPSProviderEnabled()||locationManager.isNetworkProvide
464403
else {
465404
Toast.makeText(getContext(), getString(R.string.nearby_location_not_available), Toast.LENGTH_LONG).show();
466405
}
467-
presenter.onMapReady();
406+
presenter.onMapReady(isFromSearchActivity, exploreMapController, query);
468407
registerUnregisterLocationListener(false);
469408
addOnCameraMoveListener();
470409
}
@@ -655,16 +594,14 @@ public void enableFABRecenter() {
655594

656595
@Override
657596
public void setCustomQuery(String customQuery) {
658-
this.customQuery = customQuery;
597+
this.query = query;
659598
}
660599

661600
@Override
662601
public void addNearbyMarkersToMapBoxMap(List<NearbyBaseMarker> nearbyBaseMarkers,
663602
Marker selectedMarker) {
664603
if (isMapBoxReady && mapBox != null) {
665-
//allMarkers = new ArrayList<>(nearbyBaseMarkers);
666604
mapBox.addMarkers(nearbyBaseMarkers);
667-
//setMapMarkerActions(selectedMarker);
668605
presenter.updateMapMarkersToController(nearbyBaseMarkers);
669606
}
670607
}
@@ -674,12 +611,6 @@ public void setMapBoundaries(CameraUpdate cameaUpdate) {
674611
mapBox.easeCamera(cameaUpdate);
675612
}
676613

677-
@NonNull
678-
@Override
679-
public Presenter<Media> getInjectedPresenter() {
680-
return mediaPresenter;
681-
}
682-
683614
@Override
684615
public Integer getContributionStateAt(int position) {
685616
return null;

app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapMediaDataSource.kt

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,19 @@ class ExploreMapMediaDataSource @Inject constructor(
1313
liveDataConverter: LiveDataConverter,
1414
private val mediaClient: MediaClient
1515
) : PageableBaseDataSource<Media>(liveDataConverter) {
16-
1716
fun setIsFromSearchActivity(isFromSearchActivity: Boolean) {
1817
this.isFromSearchActivity = isFromSearchActivity
1918
}
2019
override val loadFunction: LoadFunction<Media> = { loadSize: Int, startPosition: Int ->
20+
Log.d("deneme","loadFunction")
2121
//TODO: change this method
2222
// TODO: filter this result by location or display all of them on map
2323
if (isFromSearchActivity) {
24+
Log.d("deneme","isFromSearchActivity")
2425
mediaClient.getMediaListFromSearchWithLocation(query, loadSize, startPosition).blockingGet()
2526
} else {
26-
mediaClient.getMediaListFromSearchWithLocation(query, loadSize, startPosition).blockingGet()
27+
Log.d("deneme","not isFromSearchActivity")
28+
mediaClient.getMediaListFromGeoSearch(coordinate, limit).blockingGet()
2729
}
2830
}
2931
}

app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapMediaPresenterIml.kt

-21
This file was deleted.

app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapModule.kt

+3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ import fr.free.nrw.commons.explore.paging.BasePagingMapFragment
1212
@Module
1313
abstract class ExploreMapModule {
1414

15+
/*
1516
@Binds
1617
abstract fun ExploreMapMediaPresenterIml.bindsExploreMapMediaPresenter()
1718
: ExploreMapMediaPresenter
19+
20+
*/
1821
}

0 commit comments

Comments
 (0)