Skip to content

fix: update map zoom level as per radius filter change - #839

Merged
HashEngineering merged 3 commits into
feature-explore-dashfrom
bugfix-change-zoom-radius-filter
Dec 21, 2021
Merged

HashEngineering merged 3 commits into
feature-explore-dashfrom
bugfix-change-zoom-radius-filter

Conversation

@ClaudeHangui

Copy link
Copy Markdown
Contributor

Issue being fixed or feature implemented

Any change in the radius filter was not reflected zoom level of the map

Related PR's and Dependencies

Screenshots / Videos

How Has This Been Tested?

  • QA (Mobile Team)

Checklist:

  • I have performed a self-review of my own code and added comments where necessary
  • I have added or updated relevant unit/integration/functional/e2e tests

// Can be miles or kilometers, see isMetric
private val _selectedRadiusOption = MutableStateFlow(DEFAULT_RADIUS_OPTION)
var selectedRadiusOption: Int
get() = _selectedRadiusOption.value

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@ClaudeHangui
ClaudeHangui requested a review from Syn-McJ December 16, 2021 13:46

@Syn-McJ Syn-McJ left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!!)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the comment above. Here, we should use default radius value if selectedRadiusOption is null.

- use default radius value if no value is returned
@ClaudeHangui

Copy link
Copy Markdown
Contributor Author

@Syn-McJ please check out my latest changes

@Syn-McJ

Syn-McJ commented Dec 16, 2021

Copy link
Copy Markdown
Member

@Syn-McJ please check out my latest changes

@ClaudeHangui I don't see any changes?

@ClaudeHangui

Copy link
Copy Markdown
Contributor Author

@Syn-McJ snap, I forgot to push.
it's done now sorry

@Syn-McJ Syn-McJ left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great

@HashEngineering HashEngineering left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great.

@HashEngineering
HashEngineering merged commit c26b2dd into feature-explore-dash Dec 21, 2021
@HashEngineering
HashEngineering deleted the bugfix-change-zoom-radius-filter branch May 19, 2022 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants