Skip to content

Commit f342dbb

Browse files
committed
Nearby: Fix map moving by itself
fixes commons-app#6046 the OnFocusChangeListener for nearby place list items sometimes gets invoked when new items aer set, even when the list is hidden, if an item had previously been clicked in it. This in turn causes the onItemClick to be called. This commit adds a check to make sure the list is not hidden when onItemClick is invoked this way.
1 parent 4dd1605 commit f342dbb

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import android.view.View
55
import android.view.View.GONE
66
import android.view.View.INVISIBLE
77
import android.view.View.VISIBLE
8+
import android.widget.RelativeLayout
89
import androidx.activity.result.ActivityResultLauncher
910
import androidx.recyclerview.widget.LinearLayoutManager
1011
import androidx.recyclerview.widget.RecyclerView
1112
import androidx.transition.TransitionManager
13+
import com.google.android.material.bottomsheet.BottomSheetBehavior
1214
import com.hannesdorfmann.adapterdelegates4.dsl.AdapterDelegateViewBindingViewHolder
1315
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
1416
import fr.free.nrw.commons.R
@@ -42,7 +44,10 @@ fun placeAdapterDelegate(
4244
root.setOnFocusChangeListener { view1: View?, hasFocus: Boolean ->
4345
if (!hasFocus && nearbyButtonLayout.buttonLayout.isShown) {
4446
nearbyButtonLayout.buttonLayout.visibility = GONE
45-
} else if (hasFocus && !nearbyButtonLayout.buttonLayout.isShown) {
47+
} else if (hasFocus && !nearbyButtonLayout.buttonLayout.isShown &&
48+
BottomSheetBehavior.from(root.parent.parent.parent as RelativeLayout).state !=
49+
BottomSheetBehavior.STATE_HIDDEN
50+
) {
4651
showOrHideAndScrollToIfLast()
4752
onItemClick?.invoke(item)
4853
}

0 commit comments

Comments
 (0)