Filtering works

This commit is contained in:
neslihanturan 2019-10-12 14:56:36 +03:00
parent 7d75c9c589
commit 8a13cf7728
9 changed files with 117 additions and 32 deletions

View file

@ -54,6 +54,7 @@ public enum Label {
private final String text;
@DrawableRes
private final int icon;
private boolean selected;
Label(String text, @DrawableRes int icon) {
this.text = text;
@ -65,6 +66,14 @@ public enum Label {
this.icon = in.readInt();
}
public void setSelected(boolean isSelected) {
this.selected = isSelected;
}
public boolean isSelected() {
return selected;
}
public String getText() {
return text;
}

View file

@ -0,0 +1,27 @@
package fr.free.nrw.commons.nearby;
import com.mapbox.mapboxsdk.annotations.Marker;
public class MarkerPlaceGroup {
private Marker marker;
private boolean isBookmarked;
private Place place;
public MarkerPlaceGroup(Marker marker, boolean isBookmarked, Place place) {
this.marker = marker;
this.isBookmarked = isBookmarked;
this.place = place;
}
public Marker getMarker() {
return marker;
}
public Place getPlace() {
return place;
}
public boolean getIsBookmarked() {
return isBookmarked;
}
}

View file

@ -34,7 +34,7 @@ public class NearbyController {
public static LatLng latestSearchLocation; // Can be current and camera target on search this area button is used
public static double latestSearchRadius = 10.0; // Any last search radius except closest result search
public static Map<String, Marker> markerLabelMap;
public static List<MarkerPlaceGroup> markerLabelList = new ArrayList<>();
public static Map<Boolean, Marker> markerExistsMap;
public static Map<Boolean, Marker> markerNeedPicMap;

View file

@ -1,12 +1,14 @@
package fr.free.nrw.commons.nearby;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
@ -15,6 +17,7 @@ import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.nearby.presenter.NearbyParentFragmentPresenter;
public class NearbyFilterSearchRecyclerViewAdapter
extends RecyclerView.Adapter<NearbyFilterSearchRecyclerViewAdapter.RecyclerViewHolder>
@ -24,6 +27,7 @@ public class NearbyFilterSearchRecyclerViewAdapter
private Context context;
private ArrayList<Label> labels;
private ArrayList<Label> displayedLabels;
private ArrayList<Label> selectedLabels = new ArrayList<>();
public NearbyFilterSearchRecyclerViewAdapter(Context context, ArrayList<Label> labels) {
this.context = context;
@ -33,13 +37,15 @@ public class NearbyFilterSearchRecyclerViewAdapter
}
public class RecyclerViewHolder extends RecyclerView.ViewHolder {
public TextView placeLabel;
public ImageView placeIcon;
public TextView placeTypeLabel;
public ImageView placeTypeIcon;
public LinearLayout placeTypeLayout;
public RecyclerViewHolder(View view) {
super(view);
placeLabel = view.findViewById(R.id.place_text);
placeIcon = view.findViewById(R.id.place_icon);
placeTypeLabel = view.findViewById(R.id.place_text);
placeTypeIcon = view.findViewById(R.id.place_icon);
placeTypeLayout = view.findViewById(R.id.search_list_item);
}
}
@ -53,8 +59,20 @@ public class NearbyFilterSearchRecyclerViewAdapter
@Override
public void onBindViewHolder(@NonNull RecyclerViewHolder holder, int position) {
Label label = displayedLabels.get(position);
holder.placeIcon.setImageResource(label.getIcon());
holder.placeLabel.setText(label.toString());
holder.placeTypeIcon.setImageResource(label.getIcon());
holder.placeTypeLabel.setText(label.toString());
holder.placeTypeLayout.setBackgroundColor(label.isSelected() ? Color.BLUE : Color.WHITE);
holder.placeTypeLayout.setOnClickListener(view -> {
if (label.isSelected()) {
selectedLabels.remove(label);
} else {
selectedLabels.add(label);
}
label.setSelected(!label.isSelected());
holder.placeTypeLayout.setBackgroundColor(label.isSelected() ? Color.BLUE : Color.WHITE);
NearbyParentFragmentPresenter.getInstance().filterByMarkerType(selectedLabels);
});
}
@Override
@ -116,8 +134,8 @@ public class NearbyFilterSearchRecyclerViewAdapter
convertView = inflater.inflate(R.layout.nearby_search_list_item, null);
viewHolder = new RecyclerViewHolder();
viewHolder.placeLabel = convertView.findViewById(R.id.place_text);
viewHolder.placeIcon = convertView.findViewById(R.id.place_icon);
viewHolder.placeTypeLabel = convertView.findViewById(R.id.place_text);
viewHolder.placeTypeIcon = convertView.findViewById(R.id.place_icon);
convertView.setTag(viewHolder);
}
@ -128,8 +146,8 @@ public class NearbyFilterSearchRecyclerViewAdapter
Label label = displayedLabels.get(position);
if(label != null){
viewHolder.placeIcon.setImageResource(label.getIcon());
viewHolder.placeLabel.setText(label.toString());
viewHolder.placeTypeIcon.setImageResource(label.getIcon());
viewHolder.placeTypeLabel.setText(label.toString());
}
return convertView;
}

View file

@ -6,6 +6,7 @@ import com.mapbox.mapboxsdk.maps.MapboxMap;
import java.util.List;
import fr.free.nrw.commons.location.LatLng;
import fr.free.nrw.commons.nearby.Label;
import fr.free.nrw.commons.nearby.NearbyBaseMarker;
import fr.free.nrw.commons.nearby.Place;
import fr.free.nrw.commons.nearby.presenter.NearbyParentFragmentPresenter;
@ -28,6 +29,6 @@ public interface NearbyMapContract {
void centerMapToPlace(Place place, boolean isPortraitMode);
void removeCurrentLocationMarker();
List<NearbyBaseMarker> getBaseMarkerOptions();
void filterMarkersByLabels(NearbyBaseMarker nearbyBaseMarker);
void filterMarkersByLabels(List<Label> labelList);
}
}

View file

@ -8,6 +8,7 @@ import java.util.List;
import fr.free.nrw.commons.kvstore.JsonKvStore;
import fr.free.nrw.commons.location.LatLng;
import fr.free.nrw.commons.location.LocationServiceManager;
import fr.free.nrw.commons.nearby.Label;
import fr.free.nrw.commons.nearby.Place;
public interface NearbyParentFragmentContract {
@ -49,7 +50,7 @@ public interface NearbyParentFragmentContract {
void setActionListeners(JsonKvStore applicationKvStore);
void backButtonClicked();
MapboxMap.OnCameraMoveListener onCameraMove(MapboxMap mapboxMap);
void filterByMarkerType(String placeType);
void filterByMarkerType(List<Label> selectedLabels);
}
interface ViewsAreReadyCallback {

View file

@ -2,8 +2,6 @@ package fr.free.nrw.commons.nearby.fragments;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.VectorDrawable;
import android.os.Bundle;
import android.util.AttributeSet;
import android.util.Log;
@ -15,7 +13,6 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;
import com.mapbox.geojson.Feature;
import com.mapbox.mapboxsdk.annotations.Icon;
import com.mapbox.mapboxsdk.annotations.IconFactory;
import com.mapbox.mapboxsdk.annotations.Marker;
@ -29,7 +26,6 @@ import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.MapboxMapOptions;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.style.layers.SymbolLayer;
import com.mapbox.mapboxsdk.utils.MapFragmentUtils;
import java.util.ArrayList;
@ -43,6 +39,8 @@ import fr.free.nrw.commons.R;
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao;
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
import fr.free.nrw.commons.location.LatLng;
import fr.free.nrw.commons.nearby.Label;
import fr.free.nrw.commons.nearby.MarkerPlaceGroup;
import fr.free.nrw.commons.nearby.NearbyBaseMarker;
import fr.free.nrw.commons.nearby.NearbyController;
import fr.free.nrw.commons.nearby.NearbyMarker;
@ -345,14 +343,30 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment
}
@Override
public void filterMarkersByLabels(NearbyBaseMarker nearbyBaseMarker) {
Log.d("deneme55","name:"+nearbyBaseMarker.getPlace().getLabel().toString());
public void filterMarkersByLabels(List<Label> selectedLabels) {
/*Log.d("deneme55","name:"+nearbyBaseMarker.getPlace().getLabel().toString());
VectorDrawableCompat vectorDrawable = VectorDrawableCompat.create(
getContext().getResources(), R.drawable.ic_custom_greyed_out_marker, getContext().getTheme());
Bitmap icon = UiUtils.getBitmap(vectorDrawable);
NearbyController.markerLabelMap.get(nearbyBaseMarker.getPlace().getLabel().toString()).setIcon(IconFactory.getInstance(getContext()).fromBitmap(icon));
NearbyController.markerLabelList.get(nearbyBaseMarker.getPlace().getLabel().toString()).setIcon(IconFactory.getInstance(getContext()).fromBitmap(icon));
*/
if (selectedLabels.size() == 0 ) { // If nothing is selected, display all
for (MarkerPlaceGroup markerPlaceGroup : NearbyController.markerLabelList) {
updateMarker(markerPlaceGroup.getIsBookmarked(), markerPlaceGroup.getPlace(), NearbyController.currentLocation);
}
} else {
// First greyed out all markers
greyOutAllMarkers();
for (MarkerPlaceGroup markerPlaceGroup : NearbyController.markerLabelList) {
for (Label label : selectedLabels) {
if (markerPlaceGroup.getPlace().getLabel().toString().equals(label.toString())) {
updateMarker(markerPlaceGroup.getIsBookmarked(), markerPlaceGroup.getPlace(), NearbyController.currentLocation);
}
}
}
}
}
@Override
@ -374,13 +388,17 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment
Log.d("deneme66","markers:"+markers.get(0).getTitle()+", baseMarkers:"+baseMarkerList.get(0).getPlace().getName());
Log.d("deneme66","markers:"+markers.get(1).getTitle()+", baseMarkers:"+baseMarkerList.get(1).getPlace().getName());
NearbyController.markerLabelMap = new HashMap<String, Marker>();
//NearbyController.markerLabelList = new HashMap<String, MarkerPlaceGroup>();
NearbyController.markerExistsMap = new HashMap<Boolean, Marker>();
NearbyController.markerNeedPicMap = new HashMap<Boolean, Marker>();
for (int i = 0; i < baseMarkerList.size(); i++) {
// An example item: <Park, marker of that park>
NearbyController.markerLabelMap.put(baseMarkerList.get(i).getPlace().getLabel().toString(), markers.get(i));
//NearbyController.markerLabelList.put(baseMarkerList.get(i).getPlace().getLabel().toString(), markers.get(i));
NearbyBaseMarker nearbyBaseMarker = baseMarkerList.get(i);
NearbyController.markerLabelList.add(
new MarkerPlaceGroup(markers.get(i), false, nearbyBaseMarker.getPlace()));
//TODO: fix bookmark location
NearbyController.markerExistsMap.put((baseMarkerList.get(i).getPlace().hasWikidataLink()), markers.get(i));
NearbyController.markerNeedPicMap.put(((baseMarkerList.get(i).getPlace().pic == null) ? true : false), markers.get(i));
}
@ -473,6 +491,16 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment
}
}
public void greyOutAllMarkers() {
VectorDrawableCompat vectorDrawable;
vectorDrawable = VectorDrawableCompat.create(
getContext().getResources(), R.drawable.ic_custom_greyed_out_marker, getContext().getTheme());
Bitmap icon = UiUtils.getBitmap(vectorDrawable);
for (Marker marker : mapboxMap.getMarkers()) {
marker.setIcon(IconFactory.getInstance(getContext()).fromBitmap(icon));
}
}
/**
* Centers the map in nearby fragment to a given place
* @param place is new center of the map
@ -496,6 +524,5 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment
mapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(position), 1000);
}
}

View file

@ -12,6 +12,7 @@ import fr.free.nrw.commons.kvstore.JsonKvStore;
import fr.free.nrw.commons.location.LatLng;
import fr.free.nrw.commons.location.LocationServiceManager;
import fr.free.nrw.commons.location.LocationUpdateListener;
import fr.free.nrw.commons.nearby.Label;
import fr.free.nrw.commons.nearby.NearbyBaseMarker;
import fr.free.nrw.commons.nearby.NearbyController;
import fr.free.nrw.commons.nearby.Place;
@ -350,15 +351,15 @@ public class NearbyParentFragmentPresenter
}
@Override
public void filterByMarkerType(String placeType) {
List<NearbyBaseMarker> nearbyBaseMarkerList = nearbyMapFragmentView.getBaseMarkerOptions();
for (NearbyBaseMarker nearbyBaseMarker : nearbyBaseMarkerList) {
public void filterByMarkerType(List<Label> selectedLabels) {
//List<NearbyBaseMarker> nearbyBaseMarkerList = nearbyMapFragmentView.getBaseMarkerOptions();
//for (NearbyBaseMarker nearbyBaseMarker : nearbyBaseMarkerList) {
// filter from existing markers
if (!nearbyBaseMarker.getPlace().getLabel().toString().equals(placeType)) {
Log.d("deneme44",nearbyBaseMarker.getPlace().name);
nearbyMapFragmentView.filterMarkersByLabels(nearbyBaseMarker);
}
}
//if (!nearbyBaseMarker.getPlace().getLabel().toString().equals(placeType)) {
//Log.d("deneme44",nearbyBaseMarker.getPlace().name);
nearbyMapFragmentView.filterMarkersByLabels(selectedLabels);
//}
//}
}
public View.OnClickListener onSearchThisAreaClicked() {

View file

@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/search_list_item"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView