mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
Enhancement-Show Icon Labels When Long Pressed (#5492)
* Enhancement-Show Icon Labels when Long Pressed * Tests Added
This commit is contained in:
parent
a8545abff2
commit
8bafee3801
5 changed files with 67 additions and 1 deletions
|
|
@ -17,10 +17,15 @@ fun placeAdapterDelegate(
|
||||||
bookmarkLocationDao: BookmarkLocationsDao,
|
bookmarkLocationDao: BookmarkLocationsDao,
|
||||||
onItemClick: ((Place) -> Unit)? = null,
|
onItemClick: ((Place) -> Unit)? = null,
|
||||||
onCameraClicked: (Place, ActivityResultLauncher<Array<String>>) -> Unit,
|
onCameraClicked: (Place, ActivityResultLauncher<Array<String>>) -> Unit,
|
||||||
|
onCameraLongPressed: () -> Boolean,
|
||||||
onGalleryClicked: (Place) -> Unit,
|
onGalleryClicked: (Place) -> Unit,
|
||||||
|
onGalleryLongPressed: () -> Boolean,
|
||||||
onBookmarkClicked: (Place, Boolean) -> Unit,
|
onBookmarkClicked: (Place, Boolean) -> Unit,
|
||||||
|
onBookmarkLongPressed: () -> Boolean,
|
||||||
onOverflowIconClicked: (Place, View) -> Unit,
|
onOverflowIconClicked: (Place, View) -> Unit,
|
||||||
|
onOverFlowLongPressed: () -> Boolean,
|
||||||
onDirectionsClicked: (Place) -> Unit,
|
onDirectionsClicked: (Place) -> Unit,
|
||||||
|
onDirectionsLongPressed: () -> Boolean,
|
||||||
inAppCameraLocationPermissionLauncher: ActivityResultLauncher<Array<String>>
|
inAppCameraLocationPermissionLauncher: ActivityResultLauncher<Array<String>>
|
||||||
) = adapterDelegateViewBinding<Place, Place, ItemPlaceBinding>({ layoutInflater, parent ->
|
) = adapterDelegateViewBinding<Place, Place, ItemPlaceBinding>({ layoutInflater, parent ->
|
||||||
ItemPlaceBinding.inflate(layoutInflater, parent, false)
|
ItemPlaceBinding.inflate(layoutInflater, parent, false)
|
||||||
|
|
@ -39,7 +44,10 @@ fun placeAdapterDelegate(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nearbyButtonLayout.cameraButton.setOnClickListener { onCameraClicked(item, inAppCameraLocationPermissionLauncher) }
|
nearbyButtonLayout.cameraButton.setOnClickListener { onCameraClicked(item, inAppCameraLocationPermissionLauncher) }
|
||||||
|
nearbyButtonLayout.cameraButton.setOnLongClickListener { onCameraLongPressed() }
|
||||||
|
|
||||||
nearbyButtonLayout.galleryButton.setOnClickListener { onGalleryClicked(item) }
|
nearbyButtonLayout.galleryButton.setOnClickListener { onGalleryClicked(item) }
|
||||||
|
nearbyButtonLayout.galleryButton.setOnLongClickListener{onGalleryLongPressed()}
|
||||||
bookmarkButtonImage.setOnClickListener {
|
bookmarkButtonImage.setOnClickListener {
|
||||||
val isBookmarked = bookmarkLocationDao.updateBookmarkLocation(item)
|
val isBookmarked = bookmarkLocationDao.updateBookmarkLocation(item)
|
||||||
bookmarkButtonImage.setImageResource(
|
bookmarkButtonImage.setImageResource(
|
||||||
|
|
@ -47,7 +55,9 @@ fun placeAdapterDelegate(
|
||||||
)
|
)
|
||||||
onBookmarkClicked(item, isBookmarked)
|
onBookmarkClicked(item, isBookmarked)
|
||||||
}
|
}
|
||||||
|
bookmarkButtonImage.setOnLongClickListener{onBookmarkLongPressed()}
|
||||||
nearbyButtonLayout.iconOverflow.setOnClickListener { onOverflowIconClicked(item, it) }
|
nearbyButtonLayout.iconOverflow.setOnClickListener { onOverflowIconClicked(item, it) }
|
||||||
|
nearbyButtonLayout.iconOverflow.setOnLongClickListener{onOverFlowLongPressed()}
|
||||||
nearbyButtonLayout.directionsButton.setOnClickListener { onDirectionsClicked(item) }
|
nearbyButtonLayout.directionsButton.setOnClickListener { onDirectionsClicked(item) }
|
||||||
bind {
|
bind {
|
||||||
tvName.text = item.name
|
tvName.text = item.name
|
||||||
|
|
@ -74,6 +84,7 @@ fun placeAdapterDelegate(
|
||||||
R.drawable.ic_round_star_border_24px
|
R.drawable.ic_round_star_border_24px
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
nearbyButtonLayout.directionsButton.setOnLongClickListener{onDirectionsLongPressed()}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import android.content.Intent
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.widget.Toast
|
||||||
import androidx.activity.result.ActivityResultLauncher
|
import androidx.activity.result.ActivityResultLauncher
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.appcompat.widget.PopupMenu
|
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 = {
|
fun onGalleryClicked(): (Place) -> Unit = {
|
||||||
if (applicationKvStore.getBoolean("login_skipped", false)) {
|
if (applicationKvStore.getBoolean("login_skipped", false)) {
|
||||||
showLoginDialog()
|
showLoginDialog()
|
||||||
|
|
|
||||||
|
|
@ -1905,21 +1905,41 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
updateMarker(isBookmarked, selectedPlace, locationManager.getLastLocation());
|
updateMarker(isBookmarked, selectedPlace, locationManager.getLastLocation());
|
||||||
mapView.invalidate();
|
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.setVisibility(place.hasWikipediaLink() ? View.VISIBLE : View.GONE);
|
||||||
wikipediaButton.setOnClickListener(
|
wikipediaButton.setOnClickListener(
|
||||||
view -> Utils.handleWebUrl(getContext(), selectedPlace.siteLinks.getWikipediaLink()));
|
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.setVisibility(place.hasWikidataLink() ? View.VISIBLE : View.GONE);
|
||||||
wikidataButton.setOnClickListener(
|
wikidataButton.setOnClickListener(
|
||||||
view -> Utils.handleWebUrl(getContext(), selectedPlace.siteLinks.getWikidataLink()));
|
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(),
|
directionsButton.setOnClickListener(view -> Utils.handleGeoCoordinates(getActivity(),
|
||||||
selectedPlace.getLocation()));
|
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.setVisibility(selectedPlace.hasCommonsLink() ? View.VISIBLE : View.GONE);
|
||||||
commonsButton.setOnClickListener(
|
commonsButton.setOnClickListener(
|
||||||
view -> Utils.handleWebUrl(getContext(), selectedPlace.siteLinks.getCommonsLink()));
|
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());
|
icon.setImageResource(selectedPlace.getLabel().getIcon());
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,10 +18,15 @@ class PlaceAdapter(
|
||||||
bookmarkLocationsDao,
|
bookmarkLocationsDao,
|
||||||
onPlaceClicked,
|
onPlaceClicked,
|
||||||
commonPlaceClickActions.onCameraClicked(),
|
commonPlaceClickActions.onCameraClicked(),
|
||||||
|
commonPlaceClickActions.onCameraLongPressed(),
|
||||||
commonPlaceClickActions.onGalleryClicked(),
|
commonPlaceClickActions.onGalleryClicked(),
|
||||||
|
commonPlaceClickActions.onGalleryLongPressed(),
|
||||||
onBookmarkClicked,
|
onBookmarkClicked,
|
||||||
|
commonPlaceClickActions.onBookmarkLongPressed(),
|
||||||
commonPlaceClickActions.onOverflowClicked(),
|
commonPlaceClickActions.onOverflowClicked(),
|
||||||
|
commonPlaceClickActions.onOverflowLongPressed(),
|
||||||
commonPlaceClickActions.onDirectionsClicked(),
|
commonPlaceClickActions.onDirectionsClicked(),
|
||||||
|
commonPlaceClickActions.onDirectionsLongPressed(),
|
||||||
inAppCameraLocationPermissionLauncher
|
inAppCameraLocationPermissionLauncher
|
||||||
),
|
),
|
||||||
areItemsTheSame = {oldItem, newItem -> oldItem.wikiDataEntityId == newItem.wikiDataEntityId }
|
areItemsTheSame = {oldItem, newItem -> oldItem.wikiDataEntityId == newItem.wikiDataEntityId }
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,11 @@ class CommonPlaceClickActionsUnitTest {
|
||||||
Assert.assertNotNull(commonPlaceClickActions.onGalleryClicked())
|
Assert.assertNotNull(commonPlaceClickActions.onGalleryClicked())
|
||||||
Assert.assertNotNull(commonPlaceClickActions.onOverflowClicked())
|
Assert.assertNotNull(commonPlaceClickActions.onOverflowClicked())
|
||||||
Assert.assertNotNull(commonPlaceClickActions.onDirectionsClicked())
|
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
|
@Test
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue