Skip to content

Commit 8bafee3

Browse files
Enhancement-Show Icon Labels When Long Pressed (#5492)
* Enhancement-Show Icon Labels when Long Pressed * Tests Added
1 parent a8545ab commit 8bafee3

File tree

5 files changed

+67
-1
lines changed

5 files changed

+67
-1
lines changed

app/src/main/java/fr/free/nrw/commons/nearby/PlaceAdapterDelegate.kt

+11
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,15 @@ fun placeAdapterDelegate(
1717
bookmarkLocationDao: BookmarkLocationsDao,
1818
onItemClick: ((Place) -> Unit)? = null,
1919
onCameraClicked: (Place, ActivityResultLauncher<Array<String>>) -> Unit,
20+
onCameraLongPressed: () -> Boolean,
2021
onGalleryClicked: (Place) -> Unit,
22+
onGalleryLongPressed: () -> Boolean,
2123
onBookmarkClicked: (Place, Boolean) -> Unit,
24+
onBookmarkLongPressed: () -> Boolean,
2225
onOverflowIconClicked: (Place, View) -> Unit,
26+
onOverFlowLongPressed: () -> Boolean,
2327
onDirectionsClicked: (Place) -> Unit,
28+
onDirectionsLongPressed: () -> Boolean,
2429
inAppCameraLocationPermissionLauncher: ActivityResultLauncher<Array<String>>
2530
) = adapterDelegateViewBinding<Place, Place, ItemPlaceBinding>({ layoutInflater, parent ->
2631
ItemPlaceBinding.inflate(layoutInflater, parent, false)
@@ -39,15 +44,20 @@ fun placeAdapterDelegate(
3944
}
4045
}
4146
nearbyButtonLayout.cameraButton.setOnClickListener { onCameraClicked(item, inAppCameraLocationPermissionLauncher) }
47+
nearbyButtonLayout.cameraButton.setOnLongClickListener { onCameraLongPressed() }
48+
4249
nearbyButtonLayout.galleryButton.setOnClickListener { onGalleryClicked(item) }
50+
nearbyButtonLayout.galleryButton.setOnLongClickListener{onGalleryLongPressed()}
4351
bookmarkButtonImage.setOnClickListener {
4452
val isBookmarked = bookmarkLocationDao.updateBookmarkLocation(item)
4553
bookmarkButtonImage.setImageResource(
4654
if (isBookmarked) R.drawable.ic_round_star_filled_24px else R.drawable.ic_round_star_border_24px
4755
)
4856
onBookmarkClicked(item, isBookmarked)
4957
}
58+
bookmarkButtonImage.setOnLongClickListener{onBookmarkLongPressed()}
5059
nearbyButtonLayout.iconOverflow.setOnClickListener { onOverflowIconClicked(item, it) }
60+
nearbyButtonLayout.iconOverflow.setOnLongClickListener{onOverFlowLongPressed()}
5161
nearbyButtonLayout.directionsButton.setOnClickListener { onDirectionsClicked(item) }
5262
bind {
5363
tvName.text = item.name
@@ -74,6 +84,7 @@ fun placeAdapterDelegate(
7484
R.drawable.ic_round_star_border_24px
7585
)
7686
}
87+
nearbyButtonLayout.directionsButton.setOnLongClickListener{onDirectionsLongPressed()}
7788
}
7889
}
7990

app/src/main/java/fr/free/nrw/commons/nearby/fragments/CommonPlaceClickActions.kt

+25
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import android.content.Intent
55
import android.net.Uri
66
import android.view.MenuItem
77
import android.view.View
8+
import android.widget.Toast
89
import androidx.activity.result.ActivityResultLauncher
910
import androidx.appcompat.app.AlertDialog
1011
import androidx.appcompat.widget.PopupMenu
@@ -37,6 +38,30 @@ class CommonPlaceClickActions @Inject constructor(
3738
}
3839
}
3940

41+
/**
42+
* Shows the Label for the Icon when it's long pressed
43+
**/
44+
fun onCameraLongPressed(): () -> Boolean = {
45+
Toast.makeText(activity, R.string.menu_from_camera, Toast.LENGTH_SHORT).show()
46+
true
47+
}
48+
fun onGalleryLongPressed(): () -> Boolean = {
49+
Toast.makeText(activity, R.string.menu_from_gallery, Toast.LENGTH_SHORT).show()
50+
true
51+
}
52+
fun onBookmarkLongPressed(): () -> Boolean = {
53+
Toast.makeText(activity, R.string.menu_bookmark, Toast.LENGTH_SHORT).show()
54+
true
55+
}
56+
fun onDirectionsLongPressed(): () -> Boolean = {
57+
Toast.makeText(activity, R.string.nearby_directions, Toast.LENGTH_SHORT).show()
58+
true
59+
}
60+
fun onOverflowLongPressed(): () -> Boolean = {
61+
Toast.makeText(activity, R.string.more, Toast.LENGTH_SHORT).show()
62+
true
63+
}
64+
4065
fun onGalleryClicked(): (Place) -> Unit = {
4166
if (applicationKvStore.getBoolean("login_skipped", false)) {
4267
showLoginDialog()

app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java

+20
Original file line numberDiff line numberDiff line change
@@ -1905,21 +1905,41 @@ private void passInfoToSheet(final Place place) {
19051905
updateMarker(isBookmarked, selectedPlace, locationManager.getLastLocation());
19061906
mapView.invalidate();
19071907
});
1908+
bookmarkButton.setOnLongClickListener(view -> {
1909+
Toast.makeText(getContext(), R.string.menu_bookmark, Toast.LENGTH_SHORT).show();
1910+
return true;
1911+
});
19081912

19091913
wikipediaButton.setVisibility(place.hasWikipediaLink() ? View.VISIBLE : View.GONE);
19101914
wikipediaButton.setOnClickListener(
19111915
view -> Utils.handleWebUrl(getContext(), selectedPlace.siteLinks.getWikipediaLink()));
1916+
wikipediaButton.setOnLongClickListener(view -> {
1917+
Toast.makeText(getContext(), R.string.nearby_wikipedia, Toast.LENGTH_SHORT).show();
1918+
return true;
1919+
});
19121920

19131921
wikidataButton.setVisibility(place.hasWikidataLink() ? View.VISIBLE : View.GONE);
19141922
wikidataButton.setOnClickListener(
19151923
view -> Utils.handleWebUrl(getContext(), selectedPlace.siteLinks.getWikidataLink()));
1924+
wikidataButton.setOnLongClickListener(view -> {
1925+
Toast.makeText(getContext(), R.string.nearby_wikidata, Toast.LENGTH_SHORT).show();
1926+
return true;
1927+
});
19161928

19171929
directionsButton.setOnClickListener(view -> Utils.handleGeoCoordinates(getActivity(),
19181930
selectedPlace.getLocation()));
1931+
directionsButton.setOnLongClickListener(view -> {
1932+
Toast.makeText(getContext(), R.string.nearby_directions, Toast.LENGTH_SHORT).show();
1933+
return true;
1934+
});
19191935

19201936
commonsButton.setVisibility(selectedPlace.hasCommonsLink() ? View.VISIBLE : View.GONE);
19211937
commonsButton.setOnClickListener(
19221938
view -> Utils.handleWebUrl(getContext(), selectedPlace.siteLinks.getCommonsLink()));
1939+
commonsButton.setOnLongClickListener(view -> {
1940+
Toast.makeText(getContext(), R.string.nearby_commons, Toast.LENGTH_SHORT).show();
1941+
return true;
1942+
});
19231943

19241944
icon.setImageResource(selectedPlace.getLabel().getIcon());
19251945

app/src/main/java/fr/free/nrw/commons/nearby/fragments/PlaceAdapter.kt

+5
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,15 @@ class PlaceAdapter(
1818
bookmarkLocationsDao,
1919
onPlaceClicked,
2020
commonPlaceClickActions.onCameraClicked(),
21+
commonPlaceClickActions.onCameraLongPressed(),
2122
commonPlaceClickActions.onGalleryClicked(),
23+
commonPlaceClickActions.onGalleryLongPressed(),
2224
onBookmarkClicked,
25+
commonPlaceClickActions.onBookmarkLongPressed(),
2326
commonPlaceClickActions.onOverflowClicked(),
27+
commonPlaceClickActions.onOverflowLongPressed(),
2428
commonPlaceClickActions.onDirectionsClicked(),
29+
commonPlaceClickActions.onDirectionsLongPressed(),
2530
inAppCameraLocationPermissionLauncher
2631
),
2732
areItemsTheSame = {oldItem, newItem -> oldItem.wikiDataEntityId == newItem.wikiDataEntityId }

app/src/test/kotlin/fr/free/nrw/commons/nearby/CommonPlaceClickActionsUnitTest.kt

+6-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ class CommonPlaceClickActionsUnitTest {
5555
Assert.assertNotNull(commonPlaceClickActions.onGalleryClicked())
5656
Assert.assertNotNull(commonPlaceClickActions.onOverflowClicked())
5757
Assert.assertNotNull(commonPlaceClickActions.onDirectionsClicked())
58+
Assert.assertNotNull(commonPlaceClickActions.onCameraLongPressed())
59+
Assert.assertNotNull(commonPlaceClickActions.onGalleryLongPressed())
60+
Assert.assertNotNull(commonPlaceClickActions.onBookmarkLongPressed())
61+
Assert.assertNotNull(commonPlaceClickActions.onDirectionsLongPressed())
62+
Assert.assertNotNull(commonPlaceClickActions.onOverflowLongPressed())
5863
}
5964

6065
@Test
@@ -99,4 +104,4 @@ class CommonPlaceClickActionsUnitTest {
99104
method.invoke(commonPlaceClickActions)
100105
}
101106

102-
}
107+
}

0 commit comments

Comments
 (0)