This project is an Android application that displays a list of products and their details. It uses Retrofit for network requests, Gson for JSON serialization/deserialization, and Coil for image loading.
- Fetches a list of products from a remote API.
- Displays the list of products in a
RecyclerView
. - Shows product details in a separate activity when a product is clicked.
- Kotlin
- Retrofit
- Gson
- Coil
- AndroidX Libraries
- Coroutines
app/
├── src/
│ ├── main/
│ │ ├── java/com/samuelokello/chatwiseassignment/
│ │ │ ├── data/
│ │ │ │ └── remote/
│ │ │ │ └── ApiService.kt
│ │ │ ├── domain/
│ │ │ │ └── ProductRepository.kt
│ │ │ ├── ui/
│ │ │ │ ├── ProductAdapter.kt
│ │ │ │ ├── ProductDetailActivity.kt
│ │ │ │ └── ProductListActivity.kt
│ │ │ └── Product.kt
│ │ ├── res/
│ │ │ ├── layout/
│ │ │ │ ├── activity_product_detail.xml
│ │ │ │ ├── activity_product_list.xml
│ │ │ │ └── product_item.xml
│ │ │ └── values/
│ │ │ └── strings.xml
│ └── build.gradle
└── build.gradle
- Android Studio
- Kotlin 1.5+
- Gradle 7.0+
- Clone the repository:
git clone https://github.com/OkelloSam21/chatwise-assignment.git
- Open the project in Android Studio.
- Sync the project with Gradle files.
- Connect an Android device or start an emulator.
- Click on the "Run" button in Android Studio.
Defines the API endpoints using Retrofit.
interface ApiService {
@GET("products")
suspend fun getProducts(): ProductResponse
}
Handles data operations and provides a clean API for data access to the rest of the application.
class ProductRepository {
private val apiService: ApiService = // initialize Retrofit service
suspend fun getProducts(): List<Product> {
return apiService.getProducts().products
}
}
Displays a list of products using a RecyclerView
.
class ProductListActivity : AppCompatActivity() {
// Implementation details
}
Displays the details of a selected product.
class ProductDetailActivity : AppCompatActivity() {
// Implementation details
}
Adapter for the RecyclerView
in ProductListActivity
.
class ProductAdapter(
private var products: List<Product>,
private val onItemClick: (Product) -> Unit
) : RecyclerView.Adapter<ProductAdapter.ProductViewHolder>() {
// Implementation details
}
This project is licensed under the MIT License. See the LICENSE
file for details.