This commit introduces `ClusterViewModel` to manage the state and logic for fetching growth recipe recommendations.
Key functionalities:
- Manages a `StateFlow` named `_state` to represent the current state of the recommendation request (Idle, Loading, Success, Error).
- Provides a public `state` flow for observing changes in the recommendation request.
- Implements a `getRecommendation()` function that:
- Sets the state to `Loading`.
- Calls the `getRecommendation()` method of the `ClusteringRepository`.
- If successful and data is present, updates the state to `Success` with the last item from the response.
- If the response is empty, updates the state to `Error` with a "Data tidak ditemukan" message.
- Catches exceptions, maps them to user-friendly error messages, and updates the state to `Error`.
- Logs detailed error messages if fetching data fails.
This commit introduces the `ClusterScreen.kt` composable, which displays plant care recommendations.
The screen includes:
- A top app bar with the title "Rekomendasi Perawatan".
- Pull-to-refresh functionality to update recommendations.
- Display of an image based on the cluster number (1, 2, or 3).
- "Diperbarui Pada" (Updated On) timestamp, formatted to Indonesian locale.
- A "Rekomendasi" section showing general advice and specific care instructions.
- An image of a plant.
- `ListItemClustering` to display humidity, temperature, and pH values.
- Loading and error states handling.
A private `formatDate` utility function is included to format timestamps to "dd MMMM yyyy, HH:mm" in Indonesian.
This commit introduces a Koin module, `clusterNetworkModule`, to provide instances for network-related dependencies for the clustering feature.
Specifically, it provides:
- An `OkHttpClient` instance with a 5-second connection timeout.
- A `Retrofit` instance configured with a base URL ("http://labai.polinema.ac.id:5050/"), the provided `OkHttpClient`, and `GsonConverterFactory`.
- A `ClusteringService` instance created by the `Retrofit` instance.
This commit introduces the `ClusteringService` interface.
This interface defines a suspend function `getRecommendations` to fetch clustering recommendations from the "api/data" endpoint. It is expected to return a list of `ClusteringResponse` objects.