@@ -7,6 +7,7 @@ import android.content.pm.PackageManager
77import android.content.res.Configuration
88import android.location.Location
99import android.os.Bundle
10+ import android.util.Log
1011import android.view.LayoutInflater
1112import android.view.View
1213import android.view.ViewGroup
@@ -118,7 +119,6 @@ class MapFragment : Fragment() {
118119 }
119120 }
120121
121- private var initialLoadInProgress = false
122122 private var dbCallCount = 0
123123 private var lastDbCallTimeMs = 0L
124124 private var lastMerchantsGeoJson: String? = null
@@ -237,9 +237,6 @@ class MapFragment : Fragment() {
237237
238238 binding.map.getMapAsync {
239239 it.addOnCameraIdleListener {
240- if (initialLoadInProgress) {
241- initialLoadInProgress = false
242- }
243240 prefs.mapViewport = it.projection.visibleRegion.latLngBounds
244241 val center = it.projection.visibleRegion.latLngBounds.center
245242 viewLifecycleOwner.lifecycleScope.launch {
@@ -337,21 +334,28 @@ class MapFragment : Fragment() {
337334 viewLifecycleOwner.repeatOnLifecycle(Lifecycle .State .RESUMED ) {
338335 binding.sync.isVisible = true
339336
337+ Log .d(" map_fragment" , " starting sync" )
340338 val importResult = BundledPlaces .import(requireContext(), db())
341339
340+ Log .d(" map_fragment" , " imported ${importResult.placesImported} places from assets" )
342341 if (importResult.placesImported > 0 ) {
343342 setFilter(filter)
344343 }
345344
346- if (sync().syncPlaces().rowsAffected > 0 ) {
345+ Log .d(" map_fragment" , " fetching new and updated places" )
346+ val syncPlacesRes = sync().syncPlaces()
347+ Log .d(" map_fragment" , " got ${syncPlacesRes.rowsAffected} new and updated places" )
348+ if (syncPlacesRes.rowsAffected > 0 ) {
347349 setFilter(filter)
348350 }
349351
350- if (sync().syncEvents().rowsAffected > 0 ) {
352+ if (sync().syncEvents().rowsAffected > 0 && filter == Filter . EVENTS ) {
351353 setFilter(filter)
352354 }
353355
354- if (sync().syncComments().rowsAffected > 0 ) {
356+ val syncCommentsRes = sync().syncComments()
357+ Log .d(" map_fragment" , " got ${syncCommentsRes.rowsAffected} new and updated comments" )
358+ if (syncCommentsRes.rowsAffected > 0 && (filter == Filter .MERCHANTS || filter == Filter .EXCHANGES )) {
355359 setFilter(filter)
356360 }
357361
@@ -363,8 +367,6 @@ class MapFragment : Fragment() {
363367 viewLifecycleOwner, backPressedCallback
364368 )
365369
366- initialLoadInProgress = true
367-
368370 viewLifecycleOwner.lifecycleScope.launch {
369371 viewLifecycleOwner.repeatOnLifecycle(Lifecycle .State .CREATED ) {
370372 binding.map.getMapAsync {
@@ -716,10 +718,6 @@ class MapFragment : Fragment() {
716718 dbCallCount = 0
717719 lastDbCallTimeMs = 0L
718720
719- if (initialLoadInProgress) {
720- return
721- }
722-
723721 when (filter) {
724722 Filter .MERCHANTS -> showMerchants()
725723 Filter .EVENTS -> showEvents()
0 commit comments