@@ -22,7 +22,6 @@ import androidx.core.os.bundleOf
2222import androidx.core.view.ViewCompat
2323import androidx.core.view.WindowCompat
2424import androidx.core.view.WindowInsetsCompat
25- import androidx.core.view.WindowInsetsControllerCompat
2625import androidx.core.view.isVisible
2726import androidx.core.view.updateLayoutParams
2827import androidx.core.widget.doAfterTextChanged
@@ -100,19 +99,8 @@ class MapFragment : Fragment() {
10099 private var _binding : MapFragmentBinding ? = null
101100 private val binding get() = _binding !!
102101
103- private val placeFragment by lazy {
104- childFragmentManager.findFragmentById(R .id.placeFragment) as PlaceFragment
105- }
106-
107102 private lateinit var bottomSheetBehavior: BottomSheetBehavior <* >
108103
109- private val insetsController: WindowInsetsControllerCompat ? by lazy {
110- WindowCompat .getInsetsController(
111- requireActivity().window,
112- requireActivity().window.decorView
113- )
114- }
115-
116104 private var backPressedCallback = object : OnBackPressedCallback (true ) {
117105 override fun handleOnBackPressed () {
118106 onBackPressed()
@@ -184,6 +172,8 @@ class MapFragment : Fragment() {
184172 }
185173
186174 private suspend fun selectPlace (place : Place ? ) {
175+ val placeFragment =
176+ childFragmentManager.findFragmentById(R .id.placeFragment) as PlaceFragment
187177 if (place != null ) {
188178 getPlaceDetailsToolbar()
189179 placeFragment.setPlace(place)
@@ -202,7 +192,10 @@ class MapFragment : Fragment() {
202192
203193 statusBarController = MapStatusBarController (
204194 conf = resources.configuration,
205- insetsController = insetsController!! ,
195+ insetsController = WindowCompat .getInsetsController(
196+ requireActivity().window,
197+ requireActivity().window.decorView,
198+ ),
206199 bottomSheetBehavior = bottomSheetBehavior
207200 )
208201 statusBarController?.onViewCreated()
@@ -354,7 +347,10 @@ class MapFragment : Fragment() {
354347 }
355348
356349 val syncCommentsRes = sync().syncComments()
357- Log .d(" map_fragment" , " got ${syncCommentsRes.rowsAffected} new and updated comments" )
350+ Log .d(
351+ " map_fragment" ,
352+ " got ${syncCommentsRes.rowsAffected} new and updated comments"
353+ )
358354 if (syncCommentsRes.rowsAffected > 0 && (filter == Filter .MERCHANTS || filter == Filter .EXCHANGES )) {
359355 setFilter(filter)
360356 }
@@ -589,14 +585,17 @@ class MapFragment : Fragment() {
589585 }
590586
591587 override fun onSlide (bottomSheet : View , slideOffset : Float ) {
588+ val placeFragment =
589+ childFragmentManager.findFragmentById(R .id.placeFragment) as PlaceFragment
592590 placeFragment.onSlide(slideOffset)
593591 }
594592 })
595593 }
596594
597595 private suspend fun getPlaceDetailsToolbar (): Toolbar ? {
596+ val placeFragment =
597+ childFragmentManager.findFragmentById(R .id.placeFragment) as PlaceFragment
598598 var attempts = 0
599-
600599 while (placeFragment.view == null || placeFragment.requireView()
601600 .findViewById<View >(R .id.toolbar)!! .height == 0
602601 ) {
@@ -744,7 +743,7 @@ class MapFragment : Fragment() {
744743 clearOtherSources(merchantsSource)
745744 binding.map.getMapAsync { map ->
746745 val bounds = map.projection.visibleRegion.latLngBounds
747- val expandedBounds = expandBounds(bounds, CLUSTERING_SCALE_FACTOR )
746+ val expandedBounds = expandBounds(bounds)
748747 viewLifecycleOwner.lifecycleScope.launch {
749748 if (! merchantsCache.contains(expandedBounds)) {
750749 dbCallCount++
@@ -776,7 +775,7 @@ class MapFragment : Fragment() {
776775 clearOtherSources(eventsSource)
777776 binding.map.getMapAsync { map ->
778777 val bounds = map.projection.visibleRegion.latLngBounds
779- val expandedBounds = expandBounds(bounds, CLUSTERING_SCALE_FACTOR )
778+ val expandedBounds = expandBounds(bounds)
780779 viewLifecycleOwner.lifecycleScope.launch {
781780 if (! eventsCache.contains(expandedBounds)) {
782781 dbCallCount++
@@ -806,7 +805,7 @@ class MapFragment : Fragment() {
806805 clearOtherSources(exchangesSource)
807806 binding.map.getMapAsync { map ->
808807 val bounds = map.projection.visibleRegion.latLngBounds
809- val expandedBounds = expandBounds(bounds, CLUSTERING_SCALE_FACTOR )
808+ val expandedBounds = expandBounds(bounds)
810809 viewLifecycleOwner.lifecycleScope.launch {
811810 if (! exchangesCache.contains(expandedBounds)) {
812811 dbCallCount++
@@ -832,7 +831,7 @@ class MapFragment : Fragment() {
832831 }
833832 }
834833
835- private fun expandBounds (bounds : LatLngBounds , scaleFactor : Double ): LatLngBounds {
834+ private fun expandBounds (bounds : LatLngBounds , scaleFactor : Double = 2.0 ): LatLngBounds {
836835 val latSpan = bounds.latitudeSpan * scaleFactor
837836 val lonSpan = bounds.longitudeSpan * scaleFactor
838837 val center = bounds.center
@@ -846,6 +845,7 @@ class MapFragment : Fragment() {
846845 )
847846 }
848847
848+ @SuppressLint(" SetTextI18n" )
849849 private fun updateDebugStats () {
850850 val cacheSize = when (filter) {
851851 Filter .MERCHANTS -> merchantsCache.features.size
@@ -950,7 +950,6 @@ class MapFragment : Fragment() {
950950
951951 companion object {
952952 private const val MIN_QUERY_LENGTH = 3
953- private const val CLUSTERING_SCALE_FACTOR = 2.0
954953
955954 private val DISTANCE_FORMAT = NumberFormat .getNumberInstance().apply {
956955 maximumFractionDigits = 1
0 commit comments