Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…id-mvvm-template

# Conflicts:
#	app/src/main/java/com/debk007/template/presentation/viewmodel/HomeViewModel.kt
  • Loading branch information
Debashish Kundu committed Jun 11, 2024
2 parents 3a2ae95 + 84073c7 commit 5436756
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 20 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ dependencies {
debugImplementation(libs.ui.test.manifest)
implementation(libs.retrofit)
implementation(libs.moshi.converter)
ksp(libs.moshi.kotlin.codegen)
implementation(libs.glide)
implementation(libs.coroutines.android)
implementation(libs.coroutines.core)
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/java/com/debk007/template/model/Dimensions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.debk007.template.model


import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
data class Dimensions(
@Json(name = "width")
val width: Double,
@Json(name = "height")
val height: Double,
@Json(name = "depth")
val depth: Double
)
17 changes: 17 additions & 0 deletions app/src/main/java/com/debk007/template/model/Meta.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.debk007.template.model


import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
data class Meta(
@Json(name = "createdAt")
val createdAt: String,
@Json(name = "updatedAt")
val updatedAt: String,
@Json(name = "barcode")
val barcode: String,
@Json(name = "qrCode")
val qrCode: String
)
54 changes: 46 additions & 8 deletions app/src/main/java/com/debk007/template/model/ProductDetailsDTO.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,53 @@
package com.debk007.template.model

data class ProductDetailsDTO(
val brand: String,
val category: String,

import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
data class ProductDetailsDto(
@Json(name = "id")
val id: Int,
@Json(name = "title")
val title: String,
@Json(name = "description")
val description: String,
@Json(name = "category")
val category: String,
@Json(name = "price")
val price: Double,
@Json(name = "discountPercentage")
val discountPercentage: Double,
val id: Int,
val images: List<String>,
val price: Int,
@Json(name = "rating")
val rating: Double,
@Json(name = "stock")
val stock: Int,
val thumbnail: String,
val title: String
@Json(name = "tags")
val tags: List<String>,
@Json(name = "brand")
val brand: String,
@Json(name = "sku")
val sku: String,
@Json(name = "weight")
val weight: Int,
@Json(name = "dimensions")
val dimensions: Dimensions,
@Json(name = "warrantyInformation")
val warrantyInformation: String,
@Json(name = "shippingInformation")
val shippingInformation: String,
@Json(name = "availabilityStatus")
val availabilityStatus: String,
@Json(name = "reviews")
val reviews: List<Review>,
@Json(name = "returnPolicy")
val returnPolicy: String,
@Json(name = "minimumOrderQuantity")
val minimumOrderQuantity: Int,
@Json(name = "meta")
val meta: Meta,
@Json(name = "images")
val images: List<String>,
@Json(name = "thumbnail")
val thumbnail: String
)
19 changes: 19 additions & 0 deletions app/src/main/java/com/debk007/template/model/Review.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.debk007.template.model


import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
data class Review(
@Json(name = "rating")
val rating: Int,
@Json(name = "comment")
val comment: String,
@Json(name = "date")
val date: String,
@Json(name = "reviewerName")
val reviewerName: String,
@Json(name = "reviewerEmail")
val reviewerEmail: String
)
4 changes: 2 additions & 2 deletions app/src/main/java/com/debk007/template/network/ApiService.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.debk007.template.network

import com.debk007.template.model.ProductDetailsDTO
import com.debk007.template.model.ProductDetailsDto
import retrofit2.http.GET

interface ApiService {

@GET("products/1") // TODO: Set API Endpoint
suspend fun getProductDetails(): ProductDetailsDTO // TODO: Set API Response
suspend fun getProductDetails(): ProductDetailsDto // TODO: Set API Response
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import androidx.compose.runtime.State
import androidx.compose.runtime.mutableStateOf
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.debk007.template.model.ProductDetailsDTO
import com.debk007.template.model.ProductDetailsDto
import com.debk007.template.repository.Repository
import com.debk007.template.util.ApiState
import dagger.hilt.android.lifecycle.HiltViewModel
Expand All @@ -19,8 +19,9 @@ class HomeViewModel @Inject constructor(
) : ViewModel() {

// TODO: Set UI State
private val _productDetailsState: MutableState<ApiState<ProductDetailsDTO>> = mutableStateOf(ApiState.Loading)
val productDetailsState: State<ApiState<ProductDetailsDTO>> get() = _productDetailsState
private val _productDetailsState: MutableState<ApiState<ProductDetailsDto>> =
mutableStateOf(ApiState.Loading())
val productDetailsState: State<ApiState<ProductDetailsDto>> get() = _productDetailsState

init {
getProductDetails()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.debk007.template.repository

import com.debk007.template.model.ProductDetailsDTO
import com.debk007.template.model.ProductDetailsDto
import com.debk007.template.util.ApiState

interface Repository {
suspend fun getProductDetails(): ApiState<ProductDetailsDTO>
suspend fun getProductDetails(): ApiState<ProductDetailsDto>
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.debk007.template.repository

import com.debk007.template.model.ProductDetailsDTO
import com.debk007.template.model.ProductDetailsDto
import com.debk007.template.network.ApiService
import com.debk007.template.util.ApiState
import javax.inject.Inject
Expand All @@ -9,7 +9,7 @@ class RepositoryImpl @Inject constructor(
private val apiService: ApiService
) : Repository {

override suspend fun getProductDetails(): ApiState<ProductDetailsDTO> = try {
override suspend fun getProductDetails(): ApiState<ProductDetailsDto> = try {
ApiState.Success(apiService.getProductDetails())
} catch (e: Exception) {
ApiState.Error(errorMsg = e.message.toString())
Expand Down
8 changes: 5 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
[versions]
agp = "8.4.1"
agp = "8.4.2"
kotlin = "2.0.0"
core-ktx = "1.13.1"
junit = "4.13.2"
androidx-test-ext-junit = "1.1.5"
espresso-core = "3.5.1"
lifecycle-runtime-ktx = "2.8.0"
lifecycle-runtime-ktx = "2.8.1"
activity-compose = "1.9.0"
compose-bom = "2024.05.00"
moshi-kotlin-codegen = "1.15.1"
retrofit = "2.11.0"
coroutines = "1.8.0"
coroutines = "1.8.1"
hilt-navigation-compose = "1.2.0"
dagger-hilt = "2.51.1"
glide = "1.0.0-beta01"
Expand All @@ -25,6 +26,7 @@ espresso-core = { group = "androidx.test.espresso", name = "espresso-core", vers
lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifecycle-runtime-ktx" }
activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activity-compose" }
compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "compose-bom" }
moshi-kotlin-codegen = { module = "com.squareup.moshi:moshi-kotlin-codegen", version.ref = "moshi-kotlin-codegen" }
ui = { group = "androidx.compose.ui", name = "ui" }
ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" }
ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" }
Expand Down

0 comments on commit 5436756

Please sign in to comment.