Skip to content

Commit 9a8b89c

Browse files
authored
nearby: Show 'no images in this area' message instead of generic error (commons-app#5541)
1 parent 74f2e9c commit 9a8b89c

File tree

4 files changed

+46
-2
lines changed

4 files changed

+46
-2
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,13 +447,16 @@ public void populatePlaces(LatLng curLatLng) {
447447
.observeOn(AndroidSchedulers.mainThread())
448448
.subscribe(explorePlacesInfo -> {
449449
mediaList = explorePlacesInfo.mediaList;
450+
if(mediaList == null) {
451+
showResponseMessage(getString(R.string.no_pictures_in_this_area));
452+
}
450453
updateMapMarkers(explorePlacesInfo);
451454
lastMapFocus = new GeoPoint(curLatLng.getLatitude(), curLatLng.getLongitude());
452455
},
453456
throwable -> {
454457
Timber.d(throwable);
455458
showErrorMessage(getString(R.string.error_fetching_nearby_places)
456-
+ throwable.getLocalizedMessage());
459+
+ throwable.getLocalizedMessage());
457460
setProgressBarVisibility(false);
458461
presenter.lockUnlockNearby(false);
459462
}));
@@ -475,6 +478,10 @@ private void showErrorMessage(final String message) {
475478
ViewUtil.showLongToast(getActivity(), message);
476479
}
477480

481+
private void showResponseMessage(final String message) {
482+
ViewUtil.showLongSnackbar(getView(), message);
483+
}
484+
478485
@Override
479486
public void checkPermissionsAndPerformAction() {
480487
Timber.d("Checking permission and perfoming action");

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ public void updateMapMarkers(
167167
if (explorePlacesInfo.mediaList != null) {
168168
prepareNearbyBaseMarkers(explorePlacesInfo, selectedMarker);
169169
} else {
170-
//TODO: SHOW SNACKBAR
171170
lockUnlockNearby(false); // So that new ___location updates wont come
172171
exploreMapFragmentView.setProgressBarVisibility(false);
173172
}

app/src/main/java/fr/free/nrw/commons/utils/ViewUtil.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
package fr.free.nrw.commons.utils;
22

3+
import static java.security.AccessController.getContext;
4+
35
import android.app.Activity;
46
import android.content.Context;
7+
import android.graphics.Color;
58
import android.view.Display;
69
import android.view.View;
710
import android.view.inputmethod.InputMethodManager;
11+
import android.widget.TextView;
812
import android.widget.Toast;
913

1014
import androidx.annotation.StringRes;
1115

16+
import androidx.core.content.ContextCompat;
1217
import com.google.android.material.snackbar.Snackbar;
1318

19+
import fr.free.nrw.commons.R;
1420
import timber.log.Timber;
1521

1622
public class ViewUtil {
@@ -32,6 +38,37 @@ public static void showShortSnackbar(View view, int messageResourceId) {
3238
}
3339
});
3440
}
41+
public static void showLongSnackbar(View view, String text) {
42+
if(view.getContext() == null) {
43+
return;
44+
}
45+
46+
ExecutorUtils.uiExecutor().execute(()-> {
47+
try {
48+
Snackbar snackbar = Snackbar.make(view, text, Snackbar.LENGTH_SHORT);
49+
50+
View snack_view = snackbar.getView();
51+
TextView snack_text = snack_view.findViewById(R.id.snackbar_text);
52+
53+
snack_view.setBackgroundColor(Color.LTGRAY);
54+
snack_text.setTextColor(ContextCompat.getColor(view.getContext(), R.color.primaryColor));
55+
snackbar.setActionTextColor(Color.RED);
56+
57+
snackbar.setAction("Dismiss", new View.OnClickListener() {
58+
@Override
59+
public void onClick(View v) {
60+
// Handle the action click
61+
snackbar.dismiss();
62+
}
63+
});
64+
65+
snackbar.show();
66+
67+
}catch (IllegalStateException e) {
68+
Timber.e(e.getMessage());
69+
}
70+
});
71+
}
3572

3673
public static void showLongToast(Context context, String text) {
3774
if (context == null) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@
355355
<string name="rotate">Rotate</string>
356356

357357
<string name="error_fetching_nearby_places">Error fetching nearby places.</string>
358+
<string name="no_pictures_in_this_area">No pictures in this area</string>
358359
<string name="no_nearby_places_around">No nearby places around</string>
359360
<string name="error_fetching_nearby_monuments">Error fetching nearby monuments.</string>
360361
<string name="no_recent_searches">No recent searches</string>

0 commit comments

Comments
 (0)