-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Budget screen logic #10709
Budget screen logic #10709
Conversation
When updating campaign duration we also need to update the budget slider range as well as the total budget value
# Conflicts: # WooCommerce/src/main/kotlin/com/woocommerce/android/ui/blaze/creation/preview/BlazeCampaignCreationPreviewViewModel.kt
WooCommerce/src/main/res/navigation/nav_graph_blaze_campaign_creation.xml
Outdated
Show resolved
Hide resolved
…reation.xml Co-authored-by: Ondrej Ruttkay <[email protected]>
📲 You can test the changes from this Pull Request in WooCommerce Android by scanning the QR code below to install the corresponding build.
|
# Conflicts: # WooCommerce/src/main/kotlin/com/woocommerce/android/ui/blaze/creation/preview/BlazeCampaignCreationPreviewFragment.kt # WooCommerce/src/main/kotlin/com/woocommerce/android/ui/blaze/creation/preview/BlazeCampaignCreationPreviewViewModel.kt
Generated by 🚫 Danger |
fun onBudgetUpdated(sliderValue: Float) { | ||
if (sliderValue.toInt().mod(viewState.value?.durationInDays!!) == 0) { | ||
val dailySpending = sliderValue / viewState.value?.durationInDays!! | ||
_viewState.value = _viewState.value?.copy( | ||
totalBudget = sliderValue, | ||
dailySpending = formatDailySpend(dailySpending) | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the tricky part that handles updating the slider value and the budget value independently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, for some reason I just noticed that Total Spend
value is not properly updated when the duration for the campaign has larger value.
For example, set the duration to something like 25 days and then proceed to play around with the budget slider. The amount won't get correctly refreshed, it will seem unresponsive.
I'll look again into fixing that.
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## trunk #10709 +/- ##
============================================
- Coverage 41.44% 41.41% -0.04%
Complexity 5017 5017
============================================
Files 1016 1016
Lines 58364 58414 +50
Branches 7803 7810 +7
============================================
Hits 24190 24190
- Misses 32030 32080 +50
Partials 2144 2144 ☔ View full report in Codecov by Sentry. |
# Conflicts: # WooCommerce/src/main/kotlin/com/woocommerce/android/ui/blaze/creation/preview/BlazeCampaignCreationPreviewViewModel.kt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tested the PR with the slider fix and it works. I'll go ahead and merge this then.
Part of: #10574
Description
This PR adds the following missing logic to the Blaze budget screen:
The forecast updates are not part of the scope of this PR.
About the budget slider
Due to how the Composable slider works using a Float value to set the slider's position, whereas the budget value is an integer (that has to change in chunks/steps equal to the duration of the campaign), there's some flakiness to how slider responds. Between those 2 values there's some conversion from
float
toint
and some rounding that causes the total budget value displayed to skip some steps. You'll see what I mean when scrolling back and forth in the budget slider.I tested different approaches (even using thesteps
property from the slider), but none worked perfectly. The current solution is the one that works best. Of course, any ideas for improvement are welcome. Its possible I might be missing something.UPDATE: About the above. There are some real problems with the current slider implementation from this PR as explained in #10709 (comment). I fixed them in this other PR: #10739.
Testing instructions
Update
and check that all the update data is reflected in campaign preview screen.Images/gif
demoBudgetScreen.mp4