The app's functionality includes:
- Fetch a list of products form a remote api & show them in
RecyclerView
. - When an item is selected from
RecyclerView
it will load the item detials in Detail Screen. - The app uses a custom
image_cache_lib
to cache images. The library supportDISK_CACHE
andMEMORY_CACHE
. - On first load the app saves the products in a local database & on subsequent load - the items are loaded from local DB.
- The app supports
SwipeRefreshLayout
to pull to refreshRecyclerView
content from Remote source.
The app uses clean architecture with MVVM(Model View View Model)
design pattern.
MVVM provides better separation of concern, easier testing, Live data & lifecycle awareness, etc.
The UI consists of two screen
MainActivity.kt
- Initial screen. Shows list of products.DetailActivity.java
- Shows detail data about a product item.
Model is generated from JSON
data into a Kotlin data class.
In addition entity class has been added for room database along with Type converter
for saving/retrieving custom object data.
MainViewModel.kt
Used for fetching product listing & update livedata. Also send out the status of the network call like Loading, Success, Error using sealed
class.
DetailViewModel.kt
Used for converting & checking detail data.
The app uses Dagger-hilt
as a dependency injection library.
The ApplicationModule.kt
class provides Singleton
reference for Retrofit
, OkHttpClient
, Repository
etc.
The network layer is composed of Repository, ApiService.
ListingApi
- Is an interface containing the suspend functions for retrofit API call.
ListingRepository
- Holds the definition of the remote/local repository call.
You can open the project in Android studio and press run. Android Studio version used to build the project: Arctic fox 2020.3.1
Gradle plugin used in the project will require Java 11.0
to run.
you can set the gradle jdk in Preferences->Build Tools->Gradle->Gradle JDK
- Android appcompat, core, constraint layout, Material Support.
- Android View Binding
Hilt
for dependency injectionRetrofit
for REST API communicationCoroutine
for Network callLifecycle
,ViewModel
LiveData
Room
for local database.image_cache_lib
for image caching & loading.Swipe Refresh Layout
for pull-to-refreshRecyclerView
.Mockito
&Junit
for Unit testing.Robolectric
for Instrumentation testingTruth
for Assertion in testing.Espresso
for UI testing.
Unit and integration testing has been added for MainViewModel
, DetailViewModel
, ListingRepository
& ResultPercelableTest
.
Test the viewmodel of the app using CoroutineRule
& LiveData Observer
.
The test cases comprise of testing different states like Loading, Success, Error with fake data for testing listing response.
Test the Repository of the app using Robolectric
.
The test comprises of testing the functionality of Product Room Database like Insertion, Remove, Get saved listings etc.
Mock Webserver is used to test the Network api response in case of successful data, empty, failed case.
UI testing has been added for MainActivity
& DetialActivity
using Espresso
.
Initial Screen | Detail Screen |
---|---|