Hi guys. I'm working on a trading app. I need to l...
# compose
d
Hi guys. I'm working on a trading app. I need to list the user stocks and their value (profit or loss) among with the total value of the portfolio. For the holdings list, in an MVP architecture I would create a presenter for each list item but for this app I decided to use MVVM (Compose, ViewModels and Hilt ). My first idea was to create a different ViewModel for each item of LazyColumn. When using MVVM architecture, is what I'm trying to do the correct way or I should use a single ViewModel? Are you aware about any project I could have a look at? The image below is a super simplification of my actual screen, each cell is complex and that's why I wanted to use a different ViewModel for each cell. Any suggestion is very welcome.
d
I would start with single view model and if logic for single items ( mostly modify actions) will grow to large then you could consider refactoring to main view model + item view model. But i think that one view mode will be enought. The question is why those cell are complex. What I see here is one PortfolioViewModel with state of some account value and list of holdings (with basic data) and propably more complex operation on item will apear on some row action (click, long click, swipe) - This could be split to whole separate feature. So you got • read only composable with PortfolioViewModel with alll the things that you provided on that screen shot • some magic composable which replaces read only one with its own state and view model.
as you can see that separation will also help you with planing those parts of whole feature