Skip to content

Commit

Permalink
Current status, list size is working, visibility working, filter mech…
Browse files Browse the repository at this point in the history
…anism is ready
  • Loading branch information
neslihanturan committed Oct 11, 2019
1 parent 56334af commit 7d75c9c
Show file tree
Hide file tree
Showing 13 changed files with 279 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;

import com.mapbox.mapboxsdk.annotations.IconFactory;
import com.mapbox.mapboxsdk.annotations.Marker;

import java.io.IOException;
import java.util.ArrayList;
Expand Down Expand Up @@ -33,6 +34,10 @@ 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 Map<Boolean, Marker> markerExistsMap;
public static Map<Boolean, Marker> markerNeedPicMap;

@Inject
public NearbyController(NearbyPlaces nearbyPlaces) {
this.nearbyPlaces = nearbyPlaces;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
package fr.free.nrw.commons.nearby;

import android.content.Context;
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.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;

import fr.free.nrw.commons.R;

public class NearbyFilterSearchRecyclerViewAdapter
extends RecyclerView.Adapter<NearbyFilterSearchRecyclerViewAdapter.RecyclerViewHolder>
implements Filterable {

private final LayoutInflater inflater;
private Context context;
private ArrayList<Label> labels;
private ArrayList<Label> displayedLabels;

public NearbyFilterSearchRecyclerViewAdapter(Context context, ArrayList<Label> labels) {
this.context = context;
this.labels = labels;
this.displayedLabels = labels;
inflater = LayoutInflater.from(context);
}

public class RecyclerViewHolder extends RecyclerView.ViewHolder {
public TextView placeLabel;
public ImageView placeIcon;

public RecyclerViewHolder(View view) {
super(view);
placeLabel = view.findViewById(R.id.place_text);
placeIcon = view.findViewById(R.id.place_icon);
}
}

@NonNull
@Override
public RecyclerViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View itemView = inflater.inflate(R.layout.nearby_search_list_item, parent, false);
return new RecyclerViewHolder(itemView);
}

@Override
public void onBindViewHolder(@NonNull RecyclerViewHolder holder, int position) {
Label label = displayedLabels.get(position);
holder.placeIcon.setImageResource(label.getIcon());
holder.placeLabel.setText(label.toString());
}

@Override
public long getItemId(int position) {
return displayedLabels.get(position).hashCode();
}

@Override
public int getItemCount() {
return displayedLabels.size();
}

@Override
public Filter getFilter() {
return new Filter() {
@Override
protected FilterResults performFiltering(CharSequence constraint) {
FilterResults results = new FilterResults();
ArrayList<Label> filteredArrayList = new ArrayList<>();

if (labels == null) {
labels = new ArrayList<>(displayedLabels);
}

if (constraint == null || constraint.length() == 0) {
// set the Original result to return
results.count = labels.size();
results.values = labels;
} else {
constraint = constraint.toString().toLowerCase();

for (Label label : labels) {
String data = label.toString();
if (data.toLowerCase().startsWith(constraint.toString())) {
filteredArrayList.add(Label.fromText(label.getText()));
}
}

// set the Filtered result to return
results.count = filteredArrayList.size();
results.values = filteredArrayList;
}
return results;
}

@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
displayedLabels = (ArrayList<Label>) results.values; // has the filtered values
notifyDataSetChanged(); // notifies the data with new filtered values
}
};
}
/*
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
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);
convertView.setTag(viewHolder);
}
else{
//Get viewholder we already created
viewHolder = (RecyclerViewHolder)convertView.getTag();
}
Label label = displayedLabels.get(position);
if(label != null){
viewHolder.placeIcon.setImageResource(label.getIcon());
viewHolder.placeLabel.setText(label.toString());
}
return convertView;
}
*/

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@ interface View{
void addOnCameraMoveListener(MapboxMap.OnCameraMoveListener onCameraMoveListener);
void centerMapToPlace(Place place, boolean isPortraitMode);
void removeCurrentLocationMarker();
List<NearbyBaseMarker> getBaseMarkerOptions();
void filterMarkersByLabels(NearbyBaseMarker nearbyBaseMarker);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ interface UserActions {
void setActionListeners(JsonKvStore applicationKvStore);
void backButtonClicked();
MapboxMap.OnCameraMoveListener onCameraMove(MapboxMap mapboxMap);
void filterByMarkerType(String placeType);
}

interface ViewsAreReadyCallback {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

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;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -12,6 +15,7 @@
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;
Expand All @@ -25,10 +29,13 @@
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;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

Expand Down Expand Up @@ -75,6 +82,7 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment
private MapView map;
private Marker currentLocationMarker;
private Polygon currentLocationPolygon;
private List<NearbyBaseMarker> customBaseMarkerOptions;

private final double CAMERA_TARGET_SHIFT_FACTOR_PORTRAIT = 0.005;
private final double CAMERA_TARGET_SHIFT_FACTOR_LANDSCAPE = 0.004;
Expand Down Expand Up @@ -273,7 +281,7 @@ public void updateMapMarkers(LatLng latLng, List<Place> placeList
, Marker selectedMarker
, NearbyParentFragmentPresenter nearbyParentFragmentPresenter) {
Timber.d("Updates map markers");
List<NearbyBaseMarker> customBaseMarkerOptions = NearbyController
customBaseMarkerOptions = NearbyController
.loadAttractionsFromLocationToBaseMarkerOptions(latLng, // Curlatlang will be used to calculate distances
placeList,
getActivity(),
Expand Down Expand Up @@ -336,6 +344,22 @@ public void removeCurrentLocationMarker() {
mapboxMap.removePolygon(currentLocationPolygon);
}

@Override
public void filterMarkersByLabels(NearbyBaseMarker nearbyBaseMarker) {
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));

}

@Override
public List<NearbyBaseMarker> getBaseMarkerOptions() {
return customBaseMarkerOptions;
}

/**
* Adds markers to map
* @param baseMarkerList is markers will be added
Expand All @@ -346,7 +370,21 @@ public void removeCurrentLocationMarker() {
public void addNearbyMarkersToMapBoxMap(@Nullable List<NearbyBaseMarker> baseMarkerList
, Marker selectedMarker
, NearbyParentFragmentPresenter nearbyParentFragmentPresenter) {
mapboxMap.addMarkers(baseMarkerList);
List<Marker> markers = mapboxMap.addMarkers(baseMarkerList);
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.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.markerExistsMap.put((baseMarkerList.get(i).getPlace().hasWikidataLink()), markers.get(i));
NearbyController.markerNeedPicMap.put(((baseMarkerList.get(i).getPlace().pic == null) ? true : false), markers.get(i));
}

map.getMapAsync(mapboxMap -> {
mapboxMap.addMarkers(baseMarkerList);
setMapMarkerActions(selectedMarker, nearbyParentFragmentPresenter);
Expand Down Expand Up @@ -457,5 +495,7 @@ public void centerMapToPlace(Place place, boolean isPortraitMode) {
.build();
mapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(position), 1000);
}


}

Loading

0 comments on commit 7d75c9c

Please sign in to comment.