The UI layer comprises:
- UI elements built using XML.
- Android ViewModels
The ViewModels receive streams of data from use cases and repositories and transform them into UI state. The UI elements reflect this state, and provide ways for the user to interact with the app. These interactions are passed as events to the ViewModel where they are processed.
The TempCartFragment
manages temporary shopping cart functionality in the Android app.
-
ViewModels:
sharedViewModel
: Shared view model for inter-fragment communication.viewModel
: Manages UI data and interactions for the temporary cart.
-
Adapters:
verticalDealsAdapter
: Displays vertical deals.horizontalDealsAdapter
: Displays horizontal deals.productsAdapter
: Displays temporary products.comparingTableAdapter
: Displays comparing tables.comparingDealPriceAdapter
: Displays comparing deal prices.
-
Data Collections:
availableProducts
andunavailableProducts
: Lists for products in the temporary cart.industries
: List of sectors.deals
: List of deals for the selected sector.products
: List of temporary products.
-
ViewModel Initialization:
- Initialize
sharedViewModel
andviewModel
for communication and UI management.
- Initialize
-
Adapter Usage:
- Utilize adapters for displaying deals, products, and comparing tables.
-
Data Handling:
- Manage available and unavailable products, sectors, deals, and temporary product lists.
-
Lifecycle Methods:
onCreate
: Initializes the fragment and requests industries.onViewCreated
: Sets up UI components, observes LiveData, and handles clicks.
-
UI Display Modes:
- Toggle between display modes:
HORIZONTAL
,VERTICAL
, andCOMPARING_TABLE
.
- Toggle between display modes:
-
User Interactions:
- Delete/update products, review orders, and confirm items.
-
Navigation:
- Navigate to different app destinations (e.g., completion of shopping or order review).
-
Resource Handling:
- Display deals, products, and comparing tables based on data availability.
The TempCartViewModel
is responsible for managing data and business logic related to the temporary shopping cart in the Android app.
- StateFlows:
industries
: Provides information about available sectors.sectorDetail
: Represents details of a selected sector.addDealToCart
: Emits the status of adding a deal to the cart.deleteProduct
: Emits the status of deleting a product from the cart.updateProduct
: Emits the status of updating a product in the cart.currentDisplayMode
: Represents the current display mode (e.g., HORIZONTAL, VERTICAL).
-
Initialization:
- Instantiate the
TempCartViewModel
using Dagger-Hilt injection.
- Instantiate the
-
LiveData Observing:
- Observe LiveData to receive updates on industries, sector details, and cart operations.
-
Display Mode Handling:
- Use
setDisplayMode
to set the display mode for deals and products.
- Use
-
Adding a Deal to Cart:
- Call
requestAddDealToCart
to add a deal to the temporary cart.
- Call
-
Refreshing Cart:
- Use
refreshTempCart
to update the temporary cart details for a specific sector.
- Use
-
Deleting/Updating Products:
- Call
requestDeleteProduct
andrequestUpdateProduct
to handle product operations.
- Call
-
Requesting Sector Details and Confirmation:
- Use
requestSectorDetail
andrequestSectorConfirmation
to fetch sector details and confirmations.
- Use
-
Requesting Industries:
- Call
requestIndustries
to retrieve a list of available industries.
- Call
-
Error Handling:
- The ViewModel handles loading states and error responses gracefully.
-
Coroutines:
- Utilizes coroutines for asynchronous operations.
-
Dependencies:
- Utilizes various use cases for industry retrieval, cart operations, and sector details.