PetsGallery is an Android application designed to fetch and display a list of pet images. Users can view, sort, search, upload, and save images from their gallery. This project demonstrates the usage of Jetpack Compose, XML-based UI, API integration, and various Android components.
- Display pet images fetched from a remote API.
- Async image loading with caching.
- Sort images in ascending (A-Z) or descending (Z-A) order.
- Search images by title or description.
- Upload images from the user's gallery.
- Save images locally on the device.
- Light, Dark, and System theming options.
- Transition from Compose-based UI to XML-based UI.
- Error handling for failed requests.
- Unit and UI testing to ensure code reliability.
- Manages the entry point of your app.
- Sets up a
ViewModeland usesPetGalleryScreenas the primary UI composable. - Uses
Scaffoldfor a basic app structure with a top app bar and body content.
- It uses the onCreate() method to set the content using Jetpack Compose (setContent).
- Likely handles a different screen activity.
- Possibly integrates with
ComposeActivity.ktfor navigation between a compose-based screen and an XML-based UI screen.
- Configures the network API service using libraries like Retrofit.
- Enables communication with the backend server to retrieve pet images and other relevant data.
- Defines the API endpoints for interacting with the server's pet image resources (retrieving, uploading).
- Data model class representing a pet image with attributes like title, description, URL, and creation date.
- Manages the display of pet images in a list or gallery.
- Likely handles data binding for each pet image item in a
RecyclerVieworLazyColumn.
- Contains business logic and manages data fetching from the API through
PetApiService. - Provides the data to the
ViewModel.
- Acts as a middleman between the repository and the UI.
- Handles UI states (loading, success, error).
- Performs operations like saving or fetching images.
- Factory class used for creating an instance of
PetViewModelwith its dependencies (likePetRepository).
- Defines the main layout of the activity.
- Includes:
- A search bar for filtering images by title or description.
- Buttons for sorting images and uploading an image.
- A
RecyclerViewto display images in a list.
- Defines the layout for the dialog used to upload an image.
- Includes input fields for image title and description.
- Defines the layout for each item in the
RecyclerView. - Displays an image, title, description, creation date, and a button to save the image.
- Fetches images using a GET request from
https://eulerity-hackathon.appspot.com/pets. - Displays images and associated data asynchronously.
- Allows sorting images in ascending (A-Z) or descending (Z-A) order.
- Filters displayed images based on title or description.
- Enables the user to upload an image with a title and description.
- Allows the user to save an image locally to the device.
-Easy UI state change from XML-based UI to Compose-based UI
- Dark, Light, and System theme support.
This file focuses on testing the PetViewModel, which handles the business logic of the app.
- LiveData/StateFlow Testing: Uses
InstantTaskExecutorRuleto ensure LiveData updates happen immediately. - Test 1: Success State
- Mocks
PetRepositoryto return a predefined list ofPetImageobjects. - Verifies that the
PetViewModelupdates to Success state.
- Mocks
- Test 2: Error State
- Mocks the repository to throw an exception when fetching images.
- Verifies that the
ViewModelemits an Error state with an appropriate message.
This file tests the UI components of the app, specifically buttons and interactions in the pet gallery.
- Compose UI Test: Uses
createAndroidComposeRule<ComponentActivity>()for testing the Compose UI. - Test: Button Interactions
- Tests that the sorting buttons correctly trigger callbacks to change the sort order.
- Android Studio: (Latest stable version)
- I have used Android Studio Koala Feature Drop | 2024.1.2.
- Minimum SDK: 24
- Target SDK: 34
The app fetches data from the following public API:






