[perf]: Implement `ListAdapter` and `DiffUtil` in `CartAdapter.kt`
- Dominant language
- Kotlin
- Stars
- 0
- Forks
- 7
- PR merge metrics
- No merged PRs in 30d
Description
`CartAdapter.kt` currently uses `.notifyDataSetChanged()` inside the `updateList` method to refresh the RecyclerView whenever the cart changes. While this works functionally, it is one of the most expensive operations a RecyclerView adapter can perform — it blindly invalidates and redraws every single item in the list, regardless of what actually changed.
This results in visible scroll lag, dropped frames, and lost item animations on every cart update. As the cart grows, the performance cost scales linearly.
The correct approach is to replace `RecyclerView.Adapter` with `ListAdapter`, which is powered by `DiffUtil` running asynchronously on a background thread. It calculates the minimal set of changes between the old and new list and applies only those — preserving smooth 60fps scrolling and enabling native add/remove/move animations automatically.
## Current Behavior
`CartAdapter` extends `RecyclerView.Adapter` and calls `notifyDataSetChanged()` on every list update via `updateList()`. This triggers a full redraw of the entire RecyclerView on every cart change — no diff calculation, no animations, no optimization.
## Expected Behavior
List updates are calculated asynchronously using `DiffUtil`, and only the items that actually changed are redrawn. Smooth animations play automatically when items are added, removed, or moved in the cart.
## Expected Solution
- Refactor `CartAdapter` to extend `ListAdapter` instead of `RecyclerView.Adapter`.
- Implement a `DiffCallback` companion object extending `DiffUtil.ItemCallback` that checks `oldItem.item == newItem.item` for identity and `oldItem.quantity == newItem.quantity` for content equality.
- Replace the `updateList(newList)` method body with `submitList(newList.toList())`.
- Remove `notifyDataSetChanged()` entirely.
## Acceptance Criteria
- [ ] `notifyDataSetChanged()` is completely removed from the adapter.
- [ ] `list` / `ArrayList` field is removed — `currentList` is used instead wherever the list is accessed.
- [ ] The app compiles and runs without crashes after the refactor.
- [ ] A screen recording demonstrating smooth cart update animations is attached to the PR.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in CartAdapter.kt at the CartAdapter declaration and updateList method, then inspect where the adapter's list is accessed. Refactor the adapter as specified and run the app to verify compilation, cart updates, and add/remove/move animations; done means notifyDataSetChanged() and the separate list field are gone.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, kotlin
- Domain
- mobile
- Issue type
- Refactor
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100