Skip to content

Commit 8bdc4f6

Browse files
ashishkumar468Vivek Maskara
authored and
Vivek Maskara
committed
* Bug fix commons-app#1504 * Filtered messages with ConnectException [issue commons-app#1504] * A generalised message for exceptions in Nearby Activity [issue commons-app#1504]
1 parent d012572 commit 8bdc4f6

File tree

4 files changed

+29
-14
lines changed

4 files changed

+29
-14
lines changed

app/src/main/java/fr/free/nrw/commons/nearby/NearbyActivity.java

+25-4
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,22 @@
1616
import android.support.v4.app.FragmentTransaction;
1717
import android.support.v7.app.AlertDialog;
1818

19+
import android.text.TextUtils;
1920
import android.view.Menu;
2021
import android.view.MenuInflater;
2122
import android.view.MenuItem;
2223
import android.view.View;
2324
import android.widget.LinearLayout;
2425
import android.widget.ProgressBar;
2526

27+
import android.widget.Toast;
2628
import com.google.gson.Gson;
2729
import com.google.gson.GsonBuilder;
2830

31+
import io.reactivex.functions.Consumer;
32+
import java.io.IOException;
33+
import java.net.ConnectException;
34+
import java.net.UnknownHostException;
2935
import java.util.List;
3036

3137
import javax.inject.Inject;
@@ -427,8 +433,14 @@ private void refreshView(LocationServiceManager.LocationChangeType locationChang
427433
.loadAttractionsFromLocation(curLatLng))
428434
.subscribeOn(Schedulers.io())
429435
.observeOn(AndroidSchedulers.mainThread())
430-
.subscribe(this::populatePlaces);
431-
} else if (locationChangeType.equals(LocationServiceManager.LocationChangeType.LOCATION_SLIGHTLY_CHANGED)) {
436+
.subscribe(this::populatePlaces,
437+
throwable -> {
438+
Timber.d(throwable);
439+
showErrorMessage(getString(R.string.error_fetching_nearby_places));
440+
progressBar.setVisibility(View.GONE);
441+
});
442+
} else if (locationChangeType
443+
.equals(LocationServiceManager.LocationChangeType.LOCATION_SLIGHTLY_CHANGED)) {
432444
Gson gson = new GsonBuilder()
433445
.registerTypeAdapter(Uri.class, new UriSerializer())
434446
.create();
@@ -451,7 +463,7 @@ private void populatePlaces(NearbyController.NearbyPlacesInfo nearbyPlacesInfo)
451463
if (placeList.size() == 0) {
452464
ViewUtil.showSnackbar(findViewById(R.id.container), R.string.no_nearby);
453465
}
454-
466+
455467
bundle.putString("PlaceList", gsonPlaceList);
456468
//bundle.putString("CurLatLng", gsonCurLatLng);
457469
bundle.putString("BoundaryCoord", gsonBoundaryCoordinates);
@@ -580,7 +592,12 @@ private void updateMapFragment(boolean isSlightUpdate) {
580592
.loadAttractionsFromLocation(curLatLng))
581593
.subscribeOn(Schedulers.io())
582594
.observeOn(AndroidSchedulers.mainThread())
583-
.subscribe(this::populatePlaces);
595+
.subscribe(this::populatePlaces,
596+
throwable -> {
597+
Timber.d(throwable);
598+
showErrorMessage(getString(R.string.error_fetching_nearby_places));
599+
progressBar.setVisibility(View.GONE);
600+
});
584601
nearbyMapFragment.setBundleForUpdtes(bundle);
585602
nearbyMapFragment.updateMapSignificantly();
586603
updateListFragment();
@@ -646,4 +663,8 @@ public void onLocationChangedSlightly(LatLng latLng) {
646663
public void prepareViewsForSheetPosition(int bottomSheetState) {
647664
// TODO
648665
}
666+
667+
private void showErrorMessage(String message) {
668+
ViewUtil.showLongToast(NearbyActivity.this, message);
669+
}
649670
}

app/src/main/java/fr/free/nrw/commons/nearby/NearbyController.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import com.mapbox.mapboxsdk.annotations.IconFactory;
99

10+
import java.io.IOException;
1011
import java.util.ArrayList;
1112
import java.util.Collections;
1213
import java.util.HashMap;
@@ -44,7 +45,7 @@ public NearbyController(NearbyPlaces nearbyPlaces,
4445
* @return NearbyPlacesInfo a variable holds Place list without distance information
4546
* and boundary coordinates of current Place List
4647
*/
47-
public NearbyPlacesInfo loadAttractionsFromLocation(LatLng curLatLng) {
48+
public NearbyPlacesInfo loadAttractionsFromLocation(LatLng curLatLng) throws IOException {
4849

4950
Timber.d("Loading attractions near %s", curLatLng);
5051
NearbyPlacesInfo nearbyPlacesInfo = new NearbyPlacesInfo();

app/src/main/java/fr/free/nrw/commons/nearby/NearbyPlaces.java

+1-9
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,9 @@ public NearbyPlaces() {
4040
}
4141
}
4242

43-
List<Place> getFromWikidataQuery(LatLng curLatLng, String lang) {
43+
List<Place> getFromWikidataQuery(LatLng curLatLng, String lang) throws IOException {
4444
List<Place> places = Collections.emptyList();
4545

46-
try {
4746
// increase the radius gradually to find a satisfactory number of nearby places
4847
while (radius <= MAX_RADIUS) {
4948
places = getFromWikidataQuery(curLatLng, lang, radius);
@@ -54,13 +53,6 @@ List<Place> getFromWikidataQuery(LatLng curLatLng, String lang) {
5453
radius *= RADIUS_MULTIPLIER;
5554
}
5655
}
57-
} catch (IOException e) {
58-
Timber.d(e.toString());
59-
// errors tend to be caused by too many results (and time out)
60-
// try a small radius next time
61-
Timber.d("back to initial radius: %f", radius);
62-
radius = INITIAL_RADIUS;
63-
}
6456
// make sure we will be able to send at least one request next time
6557
if (radius > MAX_RADIUS) {
6658
radius = MAX_RADIUS;

app/src/main/res/values/strings.xml

+1
Original file line numberDiff line numberDiff line change
@@ -282,5 +282,6 @@
282282

283283
<string name="share_app_title">Share App</string>
284284
<string name="share_coordinates_not_present">Coordinates were not specified during image selection</string>
285+
<string name="error_fetching_nearby_places">Error fetching nearby places.</string>
285286

286287
</resources>

0 commit comments

Comments
 (0)