Refactor focus change listener to improve readability and avoid crashes (#6080)

This commit is contained in:
Sonal Yadav 2024-12-26 20:56:08 +05:30 committed by GitHub
parent 75ca96a526
commit 4244373a5d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -41,17 +41,20 @@ fun placeAdapterDelegate(
showOrHideAndScrollToIfLast()
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) {
nearbyButtonLayout.buttonLayout.visibility = GONE
} else if (hasFocus && !nearbyButtonLayout.buttonLayout.isShown &&
BottomSheetBehavior.from(root.parent.parent.parent as RelativeLayout).state !=
BottomSheetBehavior.STATE_HIDDEN
) {
} else if (hasFocus && !nearbyButtonLayout.buttonLayout.isShown) {
if (bottomSheetBehavior?.state != BottomSheetBehavior.STATE_HIDDEN) {
showOrHideAndScrollToIfLast()
onItemClick?.invoke(item)
}
}
}
nearbyButtonLayout.cameraButton.setOnClickListener { onCameraClicked(item, inAppCameraLocationPermissionLauncher, cameraPickLauncherForResult) }
nearbyButtonLayout.cameraButton.setOnLongClickListener { onCameraLongPressed() }