The PageFragment currently has multiple loadPage function signatures, which can be confusing. Additionally, PageFragmentLoadState is responsible for both core logic and UI updates, leading to a mixing of concerns. Introducing a ViewModel can help resolve both of these issues by using state management to drive UI updates once data is loaded.
This refactor can be approached in multiple stages:
- Define the data structure needed to manage the page loading process.
- Consolidate the logic from both PageFragmentLoadState and the loadPage functions into a single loader class.
- Refactor this loader class into a ViewModel to better separate concerns and handle UI updates through state changes.