mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Refactor focus change listener to improve readability and avoid crashes (#6080)
This commit is contained in:
parent
75ca96a526
commit
4244373a5d
1 changed files with 10 additions and 7 deletions
|
|
@ -41,15 +41,18 @@ fun placeAdapterDelegate(
|
||||||
showOrHideAndScrollToIfLast()
|
showOrHideAndScrollToIfLast()
|
||||||
onItemClick?.invoke(item)
|
onItemClick?.invoke(item)
|
||||||
}
|
}
|
||||||
root.setOnFocusChangeListener { view1: View?, hasFocus: Boolean ->
|
root.setOnFocusChangeListener { _: View?, hasFocus: Boolean ->
|
||||||
|
val parentView = root.parent.parent.parent as? RelativeLayout
|
||||||
|
val bottomSheetBehavior = parentView?.let { BottomSheetBehavior.from(it) }
|
||||||
|
|
||||||
|
// Hide button layout if focus is lost, otherwise show it if it's not already visible
|
||||||
if (!hasFocus && nearbyButtonLayout.buttonLayout.isShown) {
|
if (!hasFocus && nearbyButtonLayout.buttonLayout.isShown) {
|
||||||
nearbyButtonLayout.buttonLayout.visibility = GONE
|
nearbyButtonLayout.buttonLayout.visibility = GONE
|
||||||
} else if (hasFocus && !nearbyButtonLayout.buttonLayout.isShown &&
|
} else if (hasFocus && !nearbyButtonLayout.buttonLayout.isShown) {
|
||||||
BottomSheetBehavior.from(root.parent.parent.parent as RelativeLayout).state !=
|
if (bottomSheetBehavior?.state != BottomSheetBehavior.STATE_HIDDEN) {
|
||||||
BottomSheetBehavior.STATE_HIDDEN
|
showOrHideAndScrollToIfLast()
|
||||||
) {
|
onItemClick?.invoke(item)
|
||||||
showOrHideAndScrollToIfLast()
|
}
|
||||||
onItemClick?.invoke(item)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nearbyButtonLayout.cameraButton.setOnClickListener { onCameraClicked(item, inAppCameraLocationPermissionLauncher, cameraPickLauncherForResult) }
|
nearbyButtonLayout.cameraButton.setOnClickListener { onCameraClicked(item, inAppCameraLocationPermissionLauncher, cameraPickLauncherForResult) }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue