Repository navigation
fix: update map zoom level as per radius filter change - #839
Conversation
| // Can be miles or kilometers, see isMetric | ||
| private val _selectedRadiusOption = MutableStateFlow(DEFAULT_RADIUS_OPTION) | ||
| var selectedRadiusOption: Int | ||
| get() = _selectedRadiusOption.value |
There was a problem hiding this comment.
A custom setter is needed to update the radius and the changes are observed via a Livedata
| } | ||
| // In meters | ||
| val radius: Double | ||
| get() = if (isMetric) selectedRadiusOption * Const.METERS_IN_KILOMETER else selectedRadiusOption * Const.METERS_IN_MILE |
There was a problem hiding this comment.
Test cases were failing due to the value of radius not yet updated, since it depends on selectedRadiusOption which is now a livedata. We therefore needed to provide a default radius value
Syn-McJ
left a comment
There was a problem hiding this comment.
@ClaudeHangui looks good but some minor changes needed with null-value handling.
| get() = selectedRadiusOption.value?.let { | ||
| if (isMetric) it * Const.METERS_IN_KILOMETER else it * Const.METERS_IN_MILE | ||
| } ?: if (isMetric) DEFAULT_RADIUS_OPTION * Const.METERS_IN_KILOMETER | ||
| else DEFAULT_RADIUS_OPTION * Const.METERS_IN_MILE |
There was a problem hiding this comment.
This is a bit convoluted, can be simplified like:
val radius = selectedRadiusOption.value ?: DEFAULT_RADIUS_OPTION
...
| .flatMapLatest { bounds -> | ||
| _appliedFilters.postValue( | ||
| FilterOptions(query, territory, payment, selectedRadiusOption) | ||
| FilterOptions(query, territory, payment, selectedRadiusOption.value!!) |
There was a problem hiding this comment.
radius getter has a null check for the selectedRadiusOption, but here it's just assumed that it's not null. Which is likely, but not guaranteed.
It's better to use the non-null value that you already have access to in the flatMap (just need to declare it):
_selectedRadiusOption.flatMapLatest { selectedRadius ->
This one is guaranteed to be non-null.
| radiusOption, radiusOption | ||
| ) | ||
| val radiusOption = viewModel.selectedRadiusOption.value | ||
| radiusOption?.let { |
There was a problem hiding this comment.
So the searchLocation is nullable now and we're calling getString with null potentially? This is wrong, need to use the default radius value if radiusOption is null.
| binding.radiusCard.isVisible = true | ||
|
|
||
| selectedRadiusOption = viewModel.selectedRadiusOption | ||
| selectedRadiusOption = viewModel.selectedRadiusOption.value!! |
There was a problem hiding this comment.
See the comment above. Here, we should use default radius value if selectedRadiusOption is null.
- use default radius value if no value is returned
|
@Syn-McJ please check out my latest changes |
@ClaudeHangui I don't see any changes? |
|
@Syn-McJ snap, I forgot to push. |
Issue being fixed or feature implemented
Any change in the
radiusfilter was not reflected zoom level of the mapRelated PR's and Dependencies
Screenshots / Videos
How Has This Been Tested?
Checklist: