mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-30 22:34:02 +01:00 
			
		
		
		
	Add bookmarks to Nearby map (#3728)
* Remove bookmark button from row button set and put to upper level list item * Fix npe caused by lookinf for parent fragment, we don't have one anymore * style * Add new icons for bookmarked places * Change bookmarked info when bookmarked * Add pic field to bookmark dao so that we can retrieve them later * Put bookmarks as the first item of list * Add bookmark as a label * Add logic to filter nearby * remove unneeded changes * fix word * Remove logs * Remove unused part of code * Fix tests * Remove logs * simplify icon picking * remove redundant margin left * Remove non needed map and swap * Add main thread annotation * Fix tests
This commit is contained in:
		
							parent
							
								
									384afa6c44
								
							
						
					
					
						commit
						3f31c3eded
					
				
					 13 changed files with 161 additions and 90 deletions
				
			
		|  | @ -9,6 +9,7 @@ import android.os.RemoteException; | |||
| 
 | ||||
| import androidx.annotation.NonNull; | ||||
| 
 | ||||
| import fr.free.nrw.commons.nearby.NearbyController; | ||||
| import java.util.ArrayList; | ||||
| import java.util.List; | ||||
| 
 | ||||
|  | @ -74,8 +75,10 @@ public class BookmarkLocationsDao { | |||
|         boolean bookmarkExists = findBookmarkLocation(bookmarkLocation); | ||||
|         if (bookmarkExists) { | ||||
|             deleteBookmarkLocation(bookmarkLocation); | ||||
|             NearbyController.updateMarkerLabelListBookmark(bookmarkLocation, false); | ||||
|         } else { | ||||
|             addBookmarkLocation(bookmarkLocation); | ||||
|             NearbyController.updateMarkerLabelListBookmark(bookmarkLocation, true); | ||||
|         } | ||||
|         return !bookmarkExists; | ||||
|     } | ||||
|  | @ -160,10 +163,9 @@ public class BookmarkLocationsDao { | |||
|                 location, | ||||
|                 cursor.getString(cursor.getColumnIndex(Table.COLUMN_CATEGORY)), | ||||
|                 builder.build(), | ||||
|                 null, | ||||
|                 cursor.getString(cursor.getColumnIndex(Table.COLUMN_PIC)), | ||||
|                 null | ||||
|         ); | ||||
|         // TODO: add pic and destroyed to bookmark location dao | ||||
|     } | ||||
| 
 | ||||
|     private ContentValues toContentValues(Place bookmarkLocation) { | ||||
|  |  | |||
|  | @ -4,7 +4,9 @@ import android.os.Parcel; | |||
| 
 | ||||
| import androidx.annotation.DrawableRes; | ||||
| 
 | ||||
| import java.util.Arrays; | ||||
| import java.util.HashMap; | ||||
| import java.util.List; | ||||
| import java.util.Map; | ||||
| 
 | ||||
| import fr.free.nrw.commons.R; | ||||
|  | @ -17,6 +19,7 @@ import fr.free.nrw.commons.R; | |||
|  */ | ||||
| public enum Label { | ||||
| 
 | ||||
|     BOOKMARKS("BOOKMARK", R.drawable.ic_filled_star_24dp), | ||||
|     BUILDING("Q41176", R.drawable.round_icon_generic_building), | ||||
|     HOUSE("Q3947", R.drawable.round_icon_house), | ||||
|     COTTAGE("Q5783996", R.drawable.round_icon_house), | ||||
|  | @ -92,4 +95,8 @@ public enum Label { | |||
|         Label label = TEXT_TO_DESCRIPTION.get(text); | ||||
|         return label == null ? UNKNOWN : label; | ||||
|     } | ||||
| 
 | ||||
|     public static List<Label> valuesAsList() { | ||||
|         return Arrays.asList(Label.values()); | ||||
|     } | ||||
| } | ||||
|  | @ -4,6 +4,7 @@ import android.content.Context; | |||
| import android.content.res.Resources; | ||||
| import android.graphics.Bitmap; | ||||
| 
 | ||||
| import androidx.annotation.MainThread; | ||||
| import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat; | ||||
| 
 | ||||
| import com.mapbox.mapboxsdk.annotations.IconFactory; | ||||
|  | @ -14,6 +15,7 @@ import java.util.ArrayList; | |||
| import java.util.Collections; | ||||
| import java.util.HashMap; | ||||
| import java.util.List; | ||||
| import java.util.ListIterator; | ||||
| import java.util.Locale; | ||||
| import java.util.Map; | ||||
| 
 | ||||
|  | @ -166,36 +168,6 @@ public class NearbyController { | |||
|         VectorDrawableCompat vectorDrawable = null; | ||||
|         VectorDrawableCompat vectorDrawableGreen = null; | ||||
|         VectorDrawableCompat vectorDrawableGrey = null; | ||||
|         try { | ||||
|             vectorDrawable = VectorDrawableCompat.create( | ||||
|                     context.getResources(), R.drawable.ic_custom_bookmark_marker, context.getTheme() | ||||
|             ); | ||||
|         } catch (Resources.NotFoundException e) { | ||||
|             // ignore when running tests. | ||||
|         } | ||||
|         if (vectorDrawable != null) { | ||||
|             Bitmap icon = UiUtils.getBitmap(vectorDrawable); | ||||
| 
 | ||||
|             for (Place place : bookmarkplacelist) { | ||||
| 
 | ||||
|                 String distance = formatDistanceBetween(curLatLng, place.location); | ||||
|                 place.setDistance(distance); | ||||
| 
 | ||||
|                 NearbyBaseMarker nearbyBaseMarker = new NearbyBaseMarker(); | ||||
|                 nearbyBaseMarker.title(place.name); | ||||
|                 nearbyBaseMarker.position( | ||||
|                         new com.mapbox.mapboxsdk.geometry.LatLng( | ||||
|                                 place.location.getLatitude(), | ||||
|                                 place.location.getLongitude())); | ||||
|                 nearbyBaseMarker.place(place); | ||||
|                 nearbyBaseMarker.icon(IconFactory.getInstance(context) | ||||
|                         .fromBitmap(icon)); | ||||
|                 placeList.remove(place); | ||||
| 
 | ||||
|                 baseMarkerOptions.add(nearbyBaseMarker); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         vectorDrawable = null; | ||||
|         try { | ||||
|             vectorDrawable = VectorDrawableCompat.create( | ||||
|  | @ -255,4 +227,19 @@ public class NearbyController { | |||
|         public LatLng curLatLng; // Current location when this places are populated | ||||
|         public LatLng searchLatLng; // Search location for finding this places | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Updates makerLabelList item isBookmarked value | ||||
|      * @param place place which is bookmarked | ||||
|      * @param isBookmarked true is bookmarked, false if bookmark removed | ||||
|      */ | ||||
|     @MainThread | ||||
|     public static void updateMarkerLabelListBookmark(Place place, boolean isBookmarked) { | ||||
|         for (ListIterator<MarkerPlaceGroup> iter = markerLabelList.listIterator(); iter.hasNext();) { | ||||
|             MarkerPlaceGroup markerPlaceGroup = iter.next(); | ||||
|             if (markerPlaceGroup.getPlace().getWikiDataEntityId().equals(place.getWikiDataEntityId())) { | ||||
|                 iter.set(new MarkerPlaceGroup(markerPlaceGroup.getMarker(), isBookmarked, place)); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -20,6 +20,7 @@ import java.util.ArrayList; | |||
| 
 | ||||
| import fr.free.nrw.commons.R; | ||||
| import fr.free.nrw.commons.nearby.presenter.NearbyParentFragmentPresenter; | ||||
| import java.util.Collections; | ||||
| 
 | ||||
| public class NearbyFilterSearchRecyclerViewAdapter | ||||
|         extends RecyclerView.Adapter<NearbyFilterSearchRecyclerViewAdapter.RecyclerViewHolder> | ||||
|  |  | |||
|  | @ -54,9 +54,7 @@ public class PlaceRenderer extends Renderer<Place> { | |||
|     @BindView(R.id.iconOverflow) LinearLayout iconOverflow; | ||||
|     @BindView(R.id.cameraButtonText) TextView cameraButtonText; | ||||
|     @BindView(R.id.galleryButtonText) TextView galleryButtonText; | ||||
|     @BindView(R.id.bookmarkRowButton) LinearLayout bookmarkButton; | ||||
|     @BindView(R.id.bookmarkButtonText) TextView bookmarkButtonText; | ||||
|     @BindView(R.id.bookmarkRowButtonImage) ImageView bookmarkButtonImage; | ||||
|     @BindView(R.id.bookmarkButtonImage) ImageView bookmarkButtonImage; | ||||
| 
 | ||||
|     @BindView(R.id.directionsButtonText) TextView directionsButtonText; | ||||
|     @BindView(R.id.iconOverflowText) TextView iconOverflowText; | ||||
|  | @ -172,7 +170,7 @@ public class PlaceRenderer extends Renderer<Place> { | |||
|             } | ||||
|         }); | ||||
| 
 | ||||
|         bookmarkButton.setOnClickListener(view4 -> { | ||||
|         bookmarkButtonImage.setOnClickListener(view4 -> { | ||||
|             if (applicationKvStore.getBoolean("login_skipped", false)) { | ||||
|                 // prompt the user to login | ||||
|                 new AlertDialog.Builder(getContext()) | ||||
|  | @ -192,8 +190,7 @@ public class PlaceRenderer extends Renderer<Place> { | |||
|                     onBookmarkClick.onClick(); | ||||
|                 } | ||||
|                 else { | ||||
|                     ((NearbyParentFragment) (fragment.getParentFragment())). | ||||
|                             updateMarker(isBookmarked, place, null); | ||||
|                     ((NearbyParentFragment) (fragment)).updateMarker(isBookmarked, place, null); | ||||
|                 } | ||||
|             } | ||||
|         }); | ||||
|  |  | |||
|  | @ -17,6 +17,7 @@ import android.content.IntentFilter; | |||
| import android.content.pm.PackageManager; | ||||
| import android.content.res.Configuration; | ||||
| import android.graphics.Bitmap; | ||||
| import android.graphics.drawable.VectorDrawable; | ||||
| import android.os.Bundle; | ||||
| import android.provider.Settings; | ||||
| import android.util.Log; | ||||
|  | @ -34,6 +35,8 @@ import android.widget.RelativeLayout; | |||
| import android.widget.SearchView; | ||||
| import android.widget.TextView; | ||||
| import android.widget.Toast; | ||||
| 
 | ||||
| import androidx.annotation.DrawableRes; | ||||
| import androidx.annotation.NonNull; | ||||
| import androidx.annotation.Nullable; | ||||
| import androidx.recyclerview.widget.DividerItemDecoration; | ||||
|  | @ -415,7 +418,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment | |||
|         linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL); | ||||
|         recyclerView.setLayoutManager(linearLayoutManager); | ||||
| 
 | ||||
|         nearbyFilterSearchRecyclerViewAdapter = new NearbyFilterSearchRecyclerViewAdapter(getContext(),new ArrayList<>(TEXT_TO_DESCRIPTION.values()), recyclerView); | ||||
|         nearbyFilterSearchRecyclerViewAdapter = new NearbyFilterSearchRecyclerViewAdapter(getContext(), new ArrayList<>(Label.valuesAsList()), recyclerView); | ||||
|         nearbyFilterSearchRecyclerViewAdapter.setCallback(new NearbyFilterSearchRecyclerViewAdapter.Callback() { | ||||
|             @Override | ||||
|             public void setCheckboxUnknown() { | ||||
|  | @ -1131,7 +1134,8 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment | |||
|             // When label filter is engaged | ||||
|             // then compare it against place's label | ||||
|             if (selectedLabels != null && (selectedLabels.size() != 0 || !filterForPlaceState) | ||||
|                 && !selectedLabels.contains(place.getLabel())) { | ||||
|                 && (!selectedLabels.contains(place.getLabel()) | ||||
|                     && !(selectedLabels.contains(Label.BOOKMARKS) && markerPlaceGroup.getIsBookmarked()))) { | ||||
|                 continue; | ||||
|             } | ||||
| 
 | ||||
|  | @ -1172,24 +1176,9 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment | |||
|     public void updateMarker(boolean isBookmarked, Place place, @Nullable fr.free.nrw.commons.location.LatLng curLatLng) { | ||||
|         addPlaceToNearbyList(place); | ||||
| 
 | ||||
|         VectorDrawableCompat vectorDrawable; | ||||
|         if (isBookmarked) { | ||||
|             vectorDrawable = VectorDrawableCompat.create( | ||||
|                     getContext().getResources(), R.drawable.ic_custom_bookmark_marker, getContext().getTheme() | ||||
|             ); | ||||
|         } else if (!place.pic.trim().isEmpty()) { | ||||
|             vectorDrawable = VectorDrawableCompat.create( // Means place has picture | ||||
|                     getContext().getResources(), R.drawable.ic_custom_map_marker_green, getContext().getTheme() | ||||
|             ); | ||||
|         } else if (!place.destroyed.trim().isEmpty()) { // Means place is destroyed | ||||
|             vectorDrawable = VectorDrawableCompat.create( // Means place has picture | ||||
|                     getContext().getResources(), R.drawable.ic_custom_map_marker_grey, getContext().getTheme() | ||||
|             ); | ||||
|         } else { | ||||
|             vectorDrawable = VectorDrawableCompat.create( | ||||
|                     getContext().getResources(), R.drawable.ic_custom_map_marker, getContext().getTheme() | ||||
|             ); | ||||
|         } | ||||
|         VectorDrawableCompat vectorDrawable = VectorDrawableCompat.create( | ||||
|             getContext().getResources(), getIconFor(place, isBookmarked), getContext().getTheme()); | ||||
| 
 | ||||
|         for (Marker marker : mapBox.getMarkers()) { | ||||
|             if (marker.getTitle() != null && marker.getTitle().equals(place.getName())) { | ||||
| 
 | ||||
|  | @ -1213,6 +1202,22 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment | |||
|         } | ||||
|     } | ||||
| 
 | ||||
|     private @DrawableRes int getIconFor(Place place, Boolean isBookmarked) { | ||||
|         if (!place.pic.trim().isEmpty()) { | ||||
|             return (isBookmarked ? | ||||
|                 R.drawable.ic_custom_map_marker_green_bookmarked : | ||||
|                 R.drawable.ic_custom_map_marker_green); | ||||
|         } else if (!place.destroyed.trim().isEmpty()) { // Means place is destroyed | ||||
|             return (isBookmarked ? | ||||
|                 R.drawable.ic_custom_map_marker_grey_bookmarked : | ||||
|                 R.drawable.ic_custom_map_marker_grey); | ||||
|         } else { | ||||
|             return (isBookmarked ? | ||||
|                 R.drawable.ic_custom_map_marker_blue_bookmarked : | ||||
|                 R.drawable.ic_custom_map_marker); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Removes all markers except current location marker, an icon has been used | ||||
|      * but it is transparent more than grey(as the name of the icon might suggest) | ||||
|  |  | |||
|  | @ -1,7 +1,9 @@ | |||
| package fr.free.nrw.commons.nearby.presenter; | ||||
| 
 | ||||
| import android.util.Log; | ||||
| import android.view.View; | ||||
| 
 | ||||
| import androidx.annotation.MainThread; | ||||
| import com.mapbox.mapboxsdk.annotations.Marker; | ||||
| 
 | ||||
| import java.lang.reflect.Proxy; | ||||
|  | @ -301,6 +303,7 @@ public class NearbyParentFragmentPresenter | |||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     @MainThread | ||||
|     public void updateMapMarkersToController(List<NearbyBaseMarker> nearbyBaseMarkers) { | ||||
|         NearbyController.markerExistsMap = new HashMap<>(); | ||||
|         NearbyController.markerNeedPicMap = new HashMap<>(); | ||||
|  | @ -308,7 +311,7 @@ public class NearbyParentFragmentPresenter | |||
|         for (int i = 0; i < nearbyBaseMarkers.size(); i++) { | ||||
|             NearbyBaseMarker nearbyBaseMarker = nearbyBaseMarkers.get(i); | ||||
|             NearbyController.markerLabelList.add( | ||||
|                     new MarkerPlaceGroup(nearbyBaseMarkers.get(i).getMarker(), bookmarkLocationDao.findBookmarkLocation(nearbyBaseMarkers.get(i).getPlace()), nearbyBaseMarker.getPlace())); | ||||
|                     new MarkerPlaceGroup(nearbyBaseMarker.getMarker(), bookmarkLocationDao.findBookmarkLocation(nearbyBaseMarker.getPlace()), nearbyBaseMarker.getPlace())); | ||||
|             //TODO: fix bookmark location | ||||
|             NearbyController.markerExistsMap.put((nearbyBaseMarkers.get(i).getPlace().hasWikidataLink()), nearbyBaseMarkers.get(i).getMarker()); | ||||
|             NearbyController.markerNeedPicMap.put(((nearbyBaseMarkers.get(i).getPlace().pic == null) ? true : false), nearbyBaseMarkers.get(i).getMarker()); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 neslihanturan
						neslihanturan