-
Notifications
You must be signed in to change notification settings - Fork 130
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
Product list selection #7971
Product list selection #7971
Conversation
You can test the changes on this Pull Request by downloading an installable build, or scanning this QR code: |
…ist-selection # Conflicts: # WooCommerce/src/main/kotlin/com/woocommerce/android/ui/products/ProductListFragment.kt
Codecov ReportBase: 41.79% // Head: 41.85% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## trunk #7971 +/- ##
============================================
+ Coverage 41.79% 41.85% +0.06%
- Complexity 3477 3486 +9
============================================
Files 688 689 +1
Lines 37317 37463 +146
Branches 4826 4834 +8
============================================
+ Hits 15596 15682 +86
- Misses 20310 20367 +57
- Partials 1411 1414 +3
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
P2 about the changes implemented here that diverges from the task's design |
Generated by 🚫 dangerJS |
…agment Fix/list multi-select top fragment
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.
Thank you, great work @atorresveiga ! Leaving some comments
val selectionCount = tracker?.selection?.size() ?: 0 | ||
if (selectionCount > 0 && actionMode == null) { | ||
viewModel.enterSelectionMode() | ||
actionMode = (requireActivity() as AppCompatActivity) | ||
.startSupportActionMode(this@ProductListFragment) | ||
} | ||
when (selectionCount) { | ||
0 -> { | ||
viewModel.exitSelectionMode() | ||
actionMode?.finish() | ||
} | ||
else -> { | ||
actionMode?.title = StringUtils.getQuantityString( | ||
context = requireContext(), | ||
quantity = selectionCount, | ||
default = R.string.product_selection_count, | ||
one = R.string.product_selection_count_single | ||
) | ||
} | ||
} |
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.
⚙️ Can we move this logic to ViewModel? We should only pass information about selection change and a number of selected items to VM and then orchestrate changes from ViewModel.
val selectionCount = tracker?.selection?.size() ?: 0 | |
if (selectionCount > 0 && actionMode == null) { | |
viewModel.enterSelectionMode() | |
actionMode = (requireActivity() as AppCompatActivity) | |
.startSupportActionMode(this@ProductListFragment) | |
} | |
when (selectionCount) { | |
0 -> { | |
viewModel.exitSelectionMode() | |
actionMode?.finish() | |
} | |
else -> { | |
actionMode?.title = StringUtils.getQuantityString( | |
context = requireContext(), | |
quantity = selectionCount, | |
default = R.string.product_selection_count, | |
one = R.string.product_selection_count_single | |
) | |
} | |
} | |
val selectionCount = tracker?.selection?.size() ?: 0 | |
viewModel.onSelectionChanged(selectionCount) |
@@ -197,6 +199,7 @@ class ProductListViewModel @Inject constructor( | |||
} | |||
|
|||
fun onLoadMoreRequested() { | |||
if (isSelecting()) return |
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.
❓ Would pagination in a selectable state break something? If not, maybe we could allow users to load more products even if they are in selectable state?
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.
Yes, it breaks the selection state. I'll take a closer look to see if it is possible to add pagination to the selection
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 think it's generally a low priority. I think we can proceed with this feature with the behavior you proposed in this PR and then improve it later.
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 found out what the problem was, so we have list selection with pagination now 😁
sealed class ProductListState : Parcelable { | ||
@Parcelize | ||
object Selecting : ProductListState() | ||
|
||
@Parcelize | ||
object Browsing : ProductListState() |
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.
NP: as those classes have no state, maybe we could consider using enum
to reduce code
ProductListViewModel.ProductListState.Browsing -> { | ||
onListSelectionActiveChanged(false) |
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.
⚙️ We should also clear selection when entering browsing state. Otherwise, the state is inconsistent.
ProductListViewModel.ProductListState.Browsing -> { | |
onListSelectionActiveChanged(false) | |
ProductListViewModel.ProductListState.Browsing -> { | |
tracker?.clearSelection() | |
onListSelectionActiveChanged(false) |
…ulk-product-status-update # Conflicts: # WooCommerce/src/main/kotlin/com/woocommerce/android/ui/products/ProductListViewModel.kt
…add-bulk-products-update-tracks # Conflicts: # WooCommerce/src/main/kotlin/com/woocommerce/android/ui/products/ProductListViewModel.kt # WooCommerce/src/test/kotlin/com/woocommerce/android/ui/products/ProductListViewModelTest.kt
Thanks for this implementation @atorresveiga! The selection code and strategy look great, but I'm noticing some weird behavior with the selection itself. At first, I managed to use it and test all scenarios without issues, but now, when I try to select a product during the selection mode, the Product Details is called, and the selection enters a weird state. Here are some captures showing how this is happening: screencapture-1670611067907.mp4It's possible to verify that when I come back from the Product Details view, the selection state gets inconsistent, displaying 25 selected products, but the list is not reflecting that. |
…s-update-tracks feat: add tracks events for product bulk update
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.
Considering our talk on Slack and how hard it's to reproduce the issue mentioned above in a physical device. I'll approving this PR as the feature overall looks to be working nicely!
…tus-update feat: bulk update products status
…ce-update feat: update prices of selected products
…m/woocommerce/woocommerce-android into issue/7929-product-list-selection
Thanks for moving forward with the fix @atorresveiga! 🙇 It's working perfectly! I didn't manage to reproduce the issue again in any way! Amazing work! |
Closes: #7929
Closes: #7930
Why
To be able able to bulk update products, first, the merchant needs to select the products he wants to update.
Description
This task is about enabling a selectable state of the products list view. It allows product selection by using the
SelectionTracker
, part ofandroidx.recyclerview.selection
, an addon library providing support for item selection.Testing instructions
TC1
TC2
TC3
TC4
Images/gif
selection.mp4
RELEASE-NOTES.txt
if necessary.