nearby: Show 'no images in this area' message instead of generic error (#5541)

This commit is contained in:
Rohit Verma 2024-02-18 20:32:19 +05:30 committed by GitHub
parent 74f2e9cd60
commit 9a8b89c19a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 46 additions and 2 deletions

View file

@ -447,6 +447,9 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(explorePlacesInfo -> { .subscribe(explorePlacesInfo -> {
mediaList = explorePlacesInfo.mediaList; mediaList = explorePlacesInfo.mediaList;
if(mediaList == null) {
showResponseMessage(getString(R.string.no_pictures_in_this_area));
}
updateMapMarkers(explorePlacesInfo); updateMapMarkers(explorePlacesInfo);
lastMapFocus = new GeoPoint(curLatLng.getLatitude(), curLatLng.getLongitude()); lastMapFocus = new GeoPoint(curLatLng.getLatitude(), curLatLng.getLongitude());
}, },
@ -475,6 +478,10 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment
ViewUtil.showLongToast(getActivity(), message); ViewUtil.showLongToast(getActivity(), message);
} }
private void showResponseMessage(final String message) {
ViewUtil.showLongSnackbar(getView(), message);
}
@Override @Override
public void checkPermissionsAndPerformAction() { public void checkPermissionsAndPerformAction() {
Timber.d("Checking permission and perfoming action"); Timber.d("Checking permission and perfoming action");

View file

@ -167,7 +167,6 @@ public class ExploreMapPresenter
if (explorePlacesInfo.mediaList != null) { if (explorePlacesInfo.mediaList != null) {
prepareNearbyBaseMarkers(explorePlacesInfo, selectedMarker); prepareNearbyBaseMarkers(explorePlacesInfo, selectedMarker);
} else { } else {
//TODO: SHOW SNACKBAR
lockUnlockNearby(false); // So that new location updates wont come lockUnlockNearby(false); // So that new location updates wont come
exploreMapFragmentView.setProgressBarVisibility(false); exploreMapFragmentView.setProgressBarVisibility(false);
} }

View file

@ -1,16 +1,22 @@
package fr.free.nrw.commons.utils; package fr.free.nrw.commons.utils;
import static java.security.AccessController.getContext;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.graphics.Color;
import android.view.Display; import android.view.Display;
import android.view.View; import android.view.View;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.StringRes; import androidx.annotation.StringRes;
import androidx.core.content.ContextCompat;
import com.google.android.material.snackbar.Snackbar; import com.google.android.material.snackbar.Snackbar;
import fr.free.nrw.commons.R;
import timber.log.Timber; import timber.log.Timber;
public class ViewUtil { public class ViewUtil {
@ -32,6 +38,37 @@ public class ViewUtil {
} }
}); });
} }
public static void showLongSnackbar(View view, String text) {
if(view.getContext() == null) {
return;
}
ExecutorUtils.uiExecutor().execute(()-> {
try {
Snackbar snackbar = Snackbar.make(view, text, Snackbar.LENGTH_SHORT);
View snack_view = snackbar.getView();
TextView snack_text = snack_view.findViewById(R.id.snackbar_text);
snack_view.setBackgroundColor(Color.LTGRAY);
snack_text.setTextColor(ContextCompat.getColor(view.getContext(), R.color.primaryColor));
snackbar.setActionTextColor(Color.RED);
snackbar.setAction("Dismiss", new View.OnClickListener() {
@Override
public void onClick(View v) {
// Handle the action click
snackbar.dismiss();
}
});
snackbar.show();
}catch (IllegalStateException e) {
Timber.e(e.getMessage());
}
});
}
public static void showLongToast(Context context, String text) { public static void showLongToast(Context context, String text) {
if (context == null) { if (context == null) {

View file

@ -355,6 +355,7 @@
<string name="rotate">Rotate</string> <string name="rotate">Rotate</string>
<string name="error_fetching_nearby_places">Error fetching nearby places.</string> <string name="error_fetching_nearby_places">Error fetching nearby places.</string>
<string name="no_pictures_in_this_area">No pictures in this area</string>
<string name="no_nearby_places_around">No nearby places around</string> <string name="no_nearby_places_around">No nearby places around</string>
<string name="error_fetching_nearby_monuments">Error fetching nearby monuments.</string> <string name="error_fetching_nearby_monuments">Error fetching nearby monuments.</string>
<string name="no_recent_searches">No recent searches</string> <string name="no_recent_searches">No recent searches</string>