diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/PlaceAdapterDelegate.kt b/app/src/main/java/fr/free/nrw/commons/nearby/PlaceAdapterDelegate.kt index 5498176cd..5ccf2ad90 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/PlaceAdapterDelegate.kt +++ b/app/src/main/java/fr/free/nrw/commons/nearby/PlaceAdapterDelegate.kt @@ -17,10 +17,15 @@ fun placeAdapterDelegate( bookmarkLocationDao: BookmarkLocationsDao, onItemClick: ((Place) -> Unit)? = null, onCameraClicked: (Place, ActivityResultLauncher>) -> Unit, + onCameraLongPressed: () -> Boolean, onGalleryClicked: (Place) -> Unit, + onGalleryLongPressed: () -> Boolean, onBookmarkClicked: (Place, Boolean) -> Unit, + onBookmarkLongPressed: () -> Boolean, onOverflowIconClicked: (Place, View) -> Unit, + onOverFlowLongPressed: () -> Boolean, onDirectionsClicked: (Place) -> Unit, + onDirectionsLongPressed: () -> Boolean, inAppCameraLocationPermissionLauncher: ActivityResultLauncher> ) = adapterDelegateViewBinding({ layoutInflater, parent -> ItemPlaceBinding.inflate(layoutInflater, parent, false) @@ -39,7 +44,10 @@ fun placeAdapterDelegate( } } nearbyButtonLayout.cameraButton.setOnClickListener { onCameraClicked(item, inAppCameraLocationPermissionLauncher) } + nearbyButtonLayout.cameraButton.setOnLongClickListener { onCameraLongPressed() } + nearbyButtonLayout.galleryButton.setOnClickListener { onGalleryClicked(item) } + nearbyButtonLayout.galleryButton.setOnLongClickListener{onGalleryLongPressed()} bookmarkButtonImage.setOnClickListener { val isBookmarked = bookmarkLocationDao.updateBookmarkLocation(item) bookmarkButtonImage.setImageResource( @@ -47,7 +55,9 @@ fun placeAdapterDelegate( ) onBookmarkClicked(item, isBookmarked) } + bookmarkButtonImage.setOnLongClickListener{onBookmarkLongPressed()} nearbyButtonLayout.iconOverflow.setOnClickListener { onOverflowIconClicked(item, it) } + nearbyButtonLayout.iconOverflow.setOnLongClickListener{onOverFlowLongPressed()} nearbyButtonLayout.directionsButton.setOnClickListener { onDirectionsClicked(item) } bind { tvName.text = item.name @@ -74,6 +84,7 @@ fun placeAdapterDelegate( R.drawable.ic_round_star_border_24px ) } + nearbyButtonLayout.directionsButton.setOnLongClickListener{onDirectionsLongPressed()} } } diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/fragments/CommonPlaceClickActions.kt b/app/src/main/java/fr/free/nrw/commons/nearby/fragments/CommonPlaceClickActions.kt index 1b1f87737..289f25976 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/fragments/CommonPlaceClickActions.kt +++ b/app/src/main/java/fr/free/nrw/commons/nearby/fragments/CommonPlaceClickActions.kt @@ -5,6 +5,7 @@ import android.content.Intent import android.net.Uri import android.view.MenuItem import android.view.View +import android.widget.Toast import androidx.activity.result.ActivityResultLauncher import androidx.appcompat.app.AlertDialog import androidx.appcompat.widget.PopupMenu @@ -37,6 +38,30 @@ class CommonPlaceClickActions @Inject constructor( } } + /** + * Shows the Label for the Icon when it's long pressed + **/ + fun onCameraLongPressed(): () -> Boolean = { + Toast.makeText(activity, R.string.menu_from_camera, Toast.LENGTH_SHORT).show() + true + } + fun onGalleryLongPressed(): () -> Boolean = { + Toast.makeText(activity, R.string.menu_from_gallery, Toast.LENGTH_SHORT).show() + true + } + fun onBookmarkLongPressed(): () -> Boolean = { + Toast.makeText(activity, R.string.menu_bookmark, Toast.LENGTH_SHORT).show() + true + } + fun onDirectionsLongPressed(): () -> Boolean = { + Toast.makeText(activity, R.string.nearby_directions, Toast.LENGTH_SHORT).show() + true + } + fun onOverflowLongPressed(): () -> Boolean = { + Toast.makeText(activity, R.string.more, Toast.LENGTH_SHORT).show() + true + } + fun onGalleryClicked(): (Place) -> Unit = { if (applicationKvStore.getBoolean("login_skipped", false)) { showLoginDialog() diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java b/app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java index d0c8e119c..a9a47baba 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java @@ -1905,21 +1905,41 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment updateMarker(isBookmarked, selectedPlace, locationManager.getLastLocation()); mapView.invalidate(); }); + bookmarkButton.setOnLongClickListener(view -> { + Toast.makeText(getContext(), R.string.menu_bookmark, Toast.LENGTH_SHORT).show(); + return true; + }); wikipediaButton.setVisibility(place.hasWikipediaLink() ? View.VISIBLE : View.GONE); wikipediaButton.setOnClickListener( view -> Utils.handleWebUrl(getContext(), selectedPlace.siteLinks.getWikipediaLink())); + wikipediaButton.setOnLongClickListener(view -> { + Toast.makeText(getContext(), R.string.nearby_wikipedia, Toast.LENGTH_SHORT).show(); + return true; + }); wikidataButton.setVisibility(place.hasWikidataLink() ? View.VISIBLE : View.GONE); wikidataButton.setOnClickListener( view -> Utils.handleWebUrl(getContext(), selectedPlace.siteLinks.getWikidataLink())); + wikidataButton.setOnLongClickListener(view -> { + Toast.makeText(getContext(), R.string.nearby_wikidata, Toast.LENGTH_SHORT).show(); + return true; + }); directionsButton.setOnClickListener(view -> Utils.handleGeoCoordinates(getActivity(), selectedPlace.getLocation())); + directionsButton.setOnLongClickListener(view -> { + Toast.makeText(getContext(), R.string.nearby_directions, Toast.LENGTH_SHORT).show(); + return true; + }); commonsButton.setVisibility(selectedPlace.hasCommonsLink() ? View.VISIBLE : View.GONE); commonsButton.setOnClickListener( view -> Utils.handleWebUrl(getContext(), selectedPlace.siteLinks.getCommonsLink())); + commonsButton.setOnLongClickListener(view -> { + Toast.makeText(getContext(), R.string.nearby_commons, Toast.LENGTH_SHORT).show(); + return true; + }); icon.setImageResource(selectedPlace.getLabel().getIcon()); diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/fragments/PlaceAdapter.kt b/app/src/main/java/fr/free/nrw/commons/nearby/fragments/PlaceAdapter.kt index c61721bd3..e3d66e34a 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/fragments/PlaceAdapter.kt +++ b/app/src/main/java/fr/free/nrw/commons/nearby/fragments/PlaceAdapter.kt @@ -18,10 +18,15 @@ class PlaceAdapter( bookmarkLocationsDao, onPlaceClicked, commonPlaceClickActions.onCameraClicked(), + commonPlaceClickActions.onCameraLongPressed(), commonPlaceClickActions.onGalleryClicked(), + commonPlaceClickActions.onGalleryLongPressed(), onBookmarkClicked, + commonPlaceClickActions.onBookmarkLongPressed(), commonPlaceClickActions.onOverflowClicked(), + commonPlaceClickActions.onOverflowLongPressed(), commonPlaceClickActions.onDirectionsClicked(), + commonPlaceClickActions.onDirectionsLongPressed(), inAppCameraLocationPermissionLauncher ), areItemsTheSame = {oldItem, newItem -> oldItem.wikiDataEntityId == newItem.wikiDataEntityId } diff --git a/app/src/test/kotlin/fr/free/nrw/commons/nearby/CommonPlaceClickActionsUnitTest.kt b/app/src/test/kotlin/fr/free/nrw/commons/nearby/CommonPlaceClickActionsUnitTest.kt index 10a13ea24..7d0cc5eed 100644 --- a/app/src/test/kotlin/fr/free/nrw/commons/nearby/CommonPlaceClickActionsUnitTest.kt +++ b/app/src/test/kotlin/fr/free/nrw/commons/nearby/CommonPlaceClickActionsUnitTest.kt @@ -55,6 +55,11 @@ class CommonPlaceClickActionsUnitTest { Assert.assertNotNull(commonPlaceClickActions.onGalleryClicked()) Assert.assertNotNull(commonPlaceClickActions.onOverflowClicked()) Assert.assertNotNull(commonPlaceClickActions.onDirectionsClicked()) + Assert.assertNotNull(commonPlaceClickActions.onCameraLongPressed()) + Assert.assertNotNull(commonPlaceClickActions.onGalleryLongPressed()) + Assert.assertNotNull(commonPlaceClickActions.onBookmarkLongPressed()) + Assert.assertNotNull(commonPlaceClickActions.onDirectionsLongPressed()) + Assert.assertNotNull(commonPlaceClickActions.onOverflowLongPressed()) } @Test @@ -99,4 +104,4 @@ class CommonPlaceClickActionsUnitTest { method.invoke(commonPlaceClickActions) } -} \ No newline at end of file +}