├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── values
│ │ │ │ ├── colors.xml
│ │ │ │ ├── strings.xml
│ │ │ │ └── themes.xml
│ │ │ ├── values-night
│ │ │ │ └── themes.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── drawable
│ │ │ │ ├── ic_baseline_error_24.xml
│ │ │ │ ├── ic_favourite_enabled.xml
│ │ │ │ ├── ic_favourite_disabled.xml
│ │ │ │ ├── ic_add_shopping_cart.xml
│ │ │ │ ├── add_shopping_cart_24.xml
│ │ │ │ ├── ic_remove_shopping_cart.xml
│ │ │ │ ├── ic_launcher_foreground.xml
│ │ │ │ └── ic_launcher_background.xml
│ │ │ ├── xml
│ │ │ │ ├── backup_rules.xml
│ │ │ │ └── data_extraction_rules.xml
│ │ │ ├── navigation
│ │ │ │ └── nav_graph.xml
│ │ │ ├── layout
│ │ │ │ ├── activity_main.xml
│ │ │ │ ├── fragment_product_list.xml
│ │ │ │ ├── fragment_product_details.xml
│ │ │ │ └── product_card.xml
│ │ │ └── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── rimapps
│ │ │ │ └── shoppingapp
│ │ │ │ ├── di
│ │ │ │ ├── ShoppingApplication.kt
│ │ │ │ └── module
│ │ │ │ │ └── RepositoryModule.kt
│ │ │ │ ├── features
│ │ │ │ ├── productList
│ │ │ │ │ ├── business
│ │ │ │ │ │ └── Product.kt
│ │ │ │ │ ├── data
│ │ │ │ │ │ └── ProductEntity.kt
│ │ │ │ │ └── presentation
│ │ │ │ │ │ ├── ProductCardViewState.kt
│ │ │ │ │ │ ├── ProductListViewState.kt
│ │ │ │ │ │ ├── ProductListViewModel.kt
│ │ │ │ │ │ ├── ProductCardListAdapter.kt
│ │ │ │ │ │ └── ProductListFragment.kt
│ │ │ │ ├── productDetails
│ │ │ │ │ ├── data
│ │ │ │ │ │ ├── AsyncResult.kt
│ │ │ │ │ │ └── ProductDetailsEntity.kt
│ │ │ │ │ ├── business
│ │ │ │ │ │ └── ProductDetail.kt
│ │ │ │ │ └── presentation
│ │ │ │ │ │ ├── ProductDetailsViewState.kt
│ │ │ │ │ │ ├── ProductDetailsViewModel.kt
│ │ │ │ │ │ └── ProductDetailsFragment.kt
│ │ │ │ └── wishList
│ │ │ │ │ ├── repository
│ │ │ │ │ ├── WishListRepository.kt
│ │ │ │ │ └── WishListDatabaseRepository.kt
│ │ │ │ │ ├── data
│ │ │ │ │ └── FavouriteProductEntity.kt
│ │ │ │ │ ├── dataBase
│ │ │ │ │ ├── WishListDatabase.kt
│ │ │ │ │ └── WishListDao.kt
│ │ │ │ │ └── usecase
│ │ │ │ │ ├── IsProductInWishListUseCase.kt
│ │ │ │ │ └── AddOrRemoveFromWishListUseCase.kt
│ │ │ │ └── shared
│ │ │ │ ├── data
│ │ │ │ └── repository
│ │ │ │ │ ├── ProductRepository.kt
│ │ │ │ │ └── api
│ │ │ │ │ ├── ApiClient.kt
│ │ │ │ │ ├── ProductService.kt
│ │ │ │ │ └── ProductRepositoryApi.kt
│ │ │ │ └── presentation
│ │ │ │ └── MainActivity.kt
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── rimapps
│ │ │ └── shoppingapp
│ │ │ ├── ExampleUnitTest.kt
│ │ │ ├── TestCoroutineRule.kt
│ │ │ ├── features
│ │ │ ├── productList
│ │ │ │ └── presentation
│ │ │ │ │ ├── ProductListViewStateTest.kt
│ │ │ │ │ └── ProductListViewModelTest.kt
│ │ │ └── wishList
│ │ │ │ ├── repository
│ │ │ │ └── WishListDatabaseRepositoryTest.kt
│ │ │ │ └── usecase
│ │ │ │ └── AddOrRemoveFromWishListUseCaseTest.kt
│ │ │ └── shared
│ │ │ └── data
│ │ │ └── repository
│ │ │ └── api
│ │ │ └── ProductRepositoryApiTest.kt
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── rimapps
│ │ └── shoppingapp
│ │ └── ExampleInstrumentedTest.kt
├── proguard-rules.pro
└── build.gradle
├── .idea
├── .gitignore
├── compiler.xml
├── kotlinc.xml
├── vcs.xml
├── misc.xml
└── gradle.xml
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── settings.gradle
├── local.properties
├── gradle.properties
├── README.md
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rimshadpcs/ShoppingApp/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rimshadpcs/ShoppingApp/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rimshadpcs/ShoppingApp/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rimshadpcs/ShoppingApp/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rimshadpcs/ShoppingApp/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rimshadpcs/ShoppingApp/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rimshadpcs/ShoppingApp/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rimshadpcs/ShoppingApp/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rimshadpcs/ShoppingApp/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rimshadpcs/ShoppingApp/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rimshadpcs/ShoppingApp/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FF000000
4 | #FFFFFFFF
5 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/kotlinc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ShoppingApp
3 |
4 | Hello blank fragment
5 |
--------------------------------------------------------------------------------
/app/src/main/java/com/rimapps/shoppingapp/di/ShoppingApplication.kt:
--------------------------------------------------------------------------------
1 | package com.rimapps.shoppingapp.di
2 |
3 | import android.app.Application
4 | import dagger.hilt.android.HiltAndroidApp
5 |
6 | @HiltAndroidApp
7 | class ShoppingApplication: Application() {
8 | }
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu May 25 13:37:34 BST 2023
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
5 | zipStoreBase=GRADLE_USER_HOME
6 | zipStorePath=wrapper/dists
7 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 | .cxx
15 | local.properties
16 |
--------------------------------------------------------------------------------
/app/src/main/java/com/rimapps/shoppingapp/features/productList/business/Product.kt:
--------------------------------------------------------------------------------
1 | package com.rimapps.shoppingapp.features.productList.business
2 |
3 | data class Product(
4 | val title: String,
5 | val description: String,
6 | val price: Double,
7 | val imageUrl : String,
8 | val productId: String
9 | )
--------------------------------------------------------------------------------
/app/src/main/java/com/rimapps/shoppingapp/features/productDetails/data/AsyncResult.kt:
--------------------------------------------------------------------------------
1 | package com.rimapps.shoppingapp.features.productDetails.data
2 |
3 | sealed class AsyncResult {
4 | data class Error(val exception: Exception): AsyncResult()
5 | data class Success(val data:T): AsyncResult()
6 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/rimapps/shoppingapp/features/productList/data/ProductEntity.kt:
--------------------------------------------------------------------------------
1 | package com.rimapps.shoppingapp.features.productList.data
2 |
3 | data class ProductEntity(
4 | val id : String,
5 | val title: String,
6 | val description: String,
7 | val price: Double,
8 | val imageUrl : String
9 | )
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/java/com/rimapps/shoppingapp/features/wishList/repository/WishListRepository.kt:
--------------------------------------------------------------------------------
1 | package com.rimapps.shoppingapp.features.wishList.repository
2 |
3 | interface WishListRepository {
4 | suspend fun isFavourite(productId: String): Boolean
5 |
6 | suspend fun addToWishList(productId: String)
7 |
8 | suspend fun removeFromWishList(productId: String)
9 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/rimapps/shoppingapp/features/productList/presentation/ProductCardViewState.kt:
--------------------------------------------------------------------------------
1 | package com.rimapps.shoppingapp.features.productList.presentation
2 |
3 | data class ProductCardViewState(
4 | val id:String,
5 | val title: String,
6 | val description: String,
7 | val price: String,
8 | val imageUrl : String,
9 | val isFavourite: Boolean
10 | )
--------------------------------------------------------------------------------
/app/src/main/res/values-night/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | pluginManagement {
2 | repositories {
3 | google()
4 | mavenCentral()
5 | gradlePluginPortal()
6 | }
7 | }
8 | dependencyResolutionManagement {
9 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
10 | repositories {
11 | google()
12 | mavenCentral()
13 | }
14 | }
15 | rootProject.name = "ShoppingApp"
16 | include ':app'
17 |
--------------------------------------------------------------------------------
/app/src/main/java/com/rimapps/shoppingapp/features/productDetails/business/ProductDetail.kt:
--------------------------------------------------------------------------------
1 | package com.rimapps.shoppingapp.features.productDetails.business
2 |
3 | data class ProductDetail(
4 | val title: String,
5 | val description: String,
6 | val fullDescription: String,
7 | val price: String,
8 | val imageUrl : String,
9 | val pros : List,
10 | val cons : List
11 | ) {
12 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/rimapps/shoppingapp/features/wishList/data/FavouriteProductEntity.kt:
--------------------------------------------------------------------------------
1 | package com.rimapps.shoppingapp.features.wishList.data
2 |
3 | import androidx.room.ColumnInfo
4 | import androidx.room.Entity
5 | import androidx.room.PrimaryKey
6 |
7 | @Entity
8 | data class FavouriteProductEntity(
9 | @PrimaryKey val id: String,
10 | @ColumnInfo(name = "product_name") val productName: String
11 | ) {
12 | }
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/java/com/rimapps/shoppingapp/features/productDetails/data/ProductDetailsEntity.kt:
--------------------------------------------------------------------------------
1 | package com.rimapps.shoppingapp.features.productDetails.data
2 |
3 | data class ProductDetailsEntity(
4 | val title: String,
5 | val description: String,
6 | val full_description: String,
7 | val price: Double,
8 | val imageUrl : String,
9 | val pros : List,
10 | val cons : List
11 |
12 | ){
13 |
14 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_baseline_error_24.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/test/java/com/rimapps/shoppingapp/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.rimapps.shoppingapp
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
--------------------------------------------------------------------------------
/local.properties:
--------------------------------------------------------------------------------
1 | ## This file is automatically generated by Android Studio.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file should *NOT* be checked into Version Control Systems,
5 | # as it contains information specific to your local configuration.
6 | #
7 | # Location of the SDK. This is only used by Gradle.
8 | # For customization when using a Version Control System, please read the
9 | # header note.
10 | sdk.dir=/Users/rimshad/Library/Android/sdk
--------------------------------------------------------------------------------
/app/src/main/java/com/rimapps/shoppingapp/features/wishList/dataBase/WishListDatabase.kt:
--------------------------------------------------------------------------------
1 | package com.rimapps.shoppingapp.features.wishList.dataBase
2 |
3 | import androidx.room.Database
4 | import androidx.room.RoomDatabase
5 | import com.rimapps.shoppingapp.features.wishList.data.FavouriteProductEntity
6 |
7 | @Database(entities = [FavouriteProductEntity::class], version = 1)
8 | abstract class WishListDatabase : RoomDatabase() {
9 |
10 | abstract fun wishListDao():WishListDao
11 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/rimapps/shoppingapp/features/productDetails/presentation/ProductDetailsViewState.kt:
--------------------------------------------------------------------------------
1 | package com.rimapps.shoppingapp.features.productDetails.presentation
2 |
3 | import com.rimapps.shoppingapp.features.productDetails.business.ProductDetail
4 |
5 |
6 | sealed class ProductDetailsViewState {
7 | object Loading : ProductDetailsViewState()
8 | data class Content(val product: ProductDetail) : ProductDetailsViewState()
9 | object Error : ProductDetailsViewState()
10 | }
11 |
--------------------------------------------------------------------------------
/app/src/main/java/com/rimapps/shoppingapp/features/wishList/usecase/IsProductInWishListUseCase.kt:
--------------------------------------------------------------------------------
1 | package com.rimapps.shoppingapp.features.wishList.usecase
2 |
3 | import com.rimapps.shoppingapp.features.wishList.repository.WishListRepository
4 | import javax.inject.Inject
5 |
6 | class IsProductInWishListUseCase @Inject constructor(
7 | private val wishListRepository: WishListRepository
8 | ){
9 | suspend fun execute(productId: String): Boolean =
10 | wishListRepository.isFavourite(productId)
11 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_favourite_enabled.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_favourite_disabled.xml:
--------------------------------------------------------------------------------
1 |
6 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/backup_rules.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
13 |
--------------------------------------------------------------------------------
/app/src/main/java/com/rimapps/shoppingapp/shared/data/repository/ProductRepository.kt:
--------------------------------------------------------------------------------
1 | package com.rimapps.shoppingapp.shared.data.repository
2 |
3 | import com.rimapps.shoppingapp.features.productDetails.business.ProductDetail
4 | import com.rimapps.shoppingapp.features.productList.business.Product
5 | import com.rimapps.shoppingapp.features.productDetails.data.AsyncResult
6 |
7 |
8 | interface ProductRepository {
9 |
10 | suspend fun getProductList(): AsyncResult>
11 | suspend fun getProductDetails(productId: String): ProductDetail
12 |
13 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/rimapps/shoppingapp/shared/data/repository/api/ApiClient.kt:
--------------------------------------------------------------------------------
1 | package com.rimapps.shoppingapp.shared.data.repository.api
2 |
3 | import retrofit2.Retrofit
4 | import retrofit2.converter.gson.GsonConverterFactory
5 |
6 | class ApiClient {
7 |
8 | companion object {
9 | fun getService(): ProductService {
10 | return Retrofit.Builder()
11 | .baseUrl("https://us-central1-android-course-api.cloudfunctions.net/")
12 | .addConverterFactory(GsonConverterFactory.create())
13 | .build().create(ProductService::class.java)
14 | }
15 | }
16 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/rimapps/shoppingapp/shared/data/repository/api/ProductService.kt:
--------------------------------------------------------------------------------
1 | package com.rimapps.shoppingapp.shared.data.repository.api
2 |
3 | import com.rimapps.shoppingapp.features.productDetails.data.ProductDetailsEntity
4 | import com.rimapps.shoppingapp.features.productList.data.ProductEntity
5 | import retrofit2.http.GET
6 | import retrofit2.http.Query
7 |
8 | interface ProductService {
9 |
10 | @GET("products")
11 | suspend fun getProductList():List
12 |
13 | @GET("productDetails")
14 | suspend fun getProductDetails(@Query("productId") productId: String): ProductDetailsEntity
15 |
16 | }
--------------------------------------------------------------------------------
/app/src/main/res/xml/data_extraction_rules.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
12 |
13 |
19 |
--------------------------------------------------------------------------------
/app/src/main/java/com/rimapps/shoppingapp/shared/presentation/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.rimapps.shoppingapp.shared.presentation
2 |
3 | import androidx.appcompat.app.AppCompatActivity
4 | import android.os.Bundle
5 | import com.rimapps.shoppingapp.databinding.ActivityMainBinding
6 | import dagger.hilt.android.AndroidEntryPoint
7 |
8 | @AndroidEntryPoint
9 | class MainActivity : AppCompatActivity() {
10 | private lateinit var binding: ActivityMainBinding
11 |
12 | override fun onCreate(savedInstanceState: Bundle?) {
13 | super.onCreate(savedInstanceState)
14 | binding = ActivityMainBinding.inflate(layoutInflater)
15 | setContentView(binding.root)
16 | }
17 | }
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/java/com/rimapps/shoppingapp/features/wishList/dataBase/WishListDao.kt:
--------------------------------------------------------------------------------
1 | package com.rimapps.shoppingapp.features.wishList.dataBase
2 |
3 | import androidx.room.Dao
4 | import androidx.room.Delete
5 | import androidx.room.Insert
6 | import androidx.room.OnConflictStrategy
7 | import androidx.room.Query
8 | import com.rimapps.shoppingapp.features.wishList.data.FavouriteProductEntity
9 |
10 | @Dao
11 | interface WishListDao{
12 |
13 | @Query("SELECT * FROM favouriteproductentity WHERE id=:id")
14 | fun isProductFavourite(id: String): FavouriteProductEntity?
15 |
16 | @Insert
17 | fun addProductToFavourite(productEntity: FavouriteProductEntity)
18 |
19 | @Delete
20 | fun removeProductFromFavourite(product: FavouriteProductEntity)
21 | }
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_add_shopping_cart.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/java/com/rimapps/shoppingapp/features/wishList/usecase/AddOrRemoveFromWishListUseCase.kt:
--------------------------------------------------------------------------------
1 | package com.rimapps.shoppingapp.features.wishList.usecase
2 |
3 | import com.rimapps.shoppingapp.features.wishList.repository.WishListRepository
4 | import javax.inject.Inject
5 |
6 | class AddOrRemoveFromWishListUseCase @Inject constructor(
7 | private val wishListRepository: WishListRepository,
8 | private val isProductInWishListUseCase: IsProductInWishListUseCase
9 | ) {
10 | suspend fun execute(productId:String){
11 | if(isProductInWishListUseCase.execute(productId)){
12 | wishListRepository.removeFromWishList(productId)
13 | }
14 | else{
15 | wishListRepository.addToWishList(productId)
16 | }
17 | }
18 |
19 |
20 |
21 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/add_shopping_cart_24.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_remove_shopping_cart.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/rimapps/shoppingapp/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.rimapps.shoppingapp
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("com.rimapps.shoppingapp", appContext.packageName)
23 | }
24 | }
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
--------------------------------------------------------------------------------
/app/src/main/java/com/rimapps/shoppingapp/features/productList/presentation/ProductListViewState.kt:
--------------------------------------------------------------------------------
1 | package com.rimapps.shoppingapp.features.productList.presentation
2 |
3 | sealed class ProductListViewState {
4 |
5 | object Loading: ProductListViewState()
6 |
7 | data class Content(val productList:List): ProductListViewState()
8 |
9 | object Error: ProductListViewState()
10 |
11 | }
12 | fun ProductListViewState.Content.updateFavoriteProduct(
13 | productId: String,
14 | isFavorite: Boolean
15 | ): ProductListViewState.Content {
16 | return ProductListViewState.Content(productList = this.productList.map { viewState ->
17 | if (viewState.id == productId) {
18 | viewState.copy(isFavourite = isFavorite)
19 | } else {
20 | viewState
21 | }
22 | }
23 | )
24 | }
25 |
--------------------------------------------------------------------------------
/app/src/main/res/navigation/nav_graph.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
14 |
15 |
19 |
--------------------------------------------------------------------------------
/app/src/test/java/com/rimapps/shoppingapp/TestCoroutineRule.kt:
--------------------------------------------------------------------------------
1 | package com.rimapps.shoppingapp
2 |
3 | import kotlinx.coroutines.Dispatchers
4 | import kotlinx.coroutines.ExperimentalCoroutinesApi
5 | import kotlinx.coroutines.test.*
6 | import org.junit.rules.TestRule
7 | import org.junit.runner.Description
8 | import org.junit.runners.model.Statement
9 |
10 | class TestCoroutineRule: TestRule {
11 |
12 | val testCoroutineDispatcher = StandardTestDispatcher()
13 | private val testScope = TestScope(testCoroutineDispatcher)
14 |
15 | override fun apply(base: Statement, description: Description): Statement = object : Statement() {
16 | @Throws(Throwable::class)
17 | override fun evaluate() {
18 | Dispatchers.setMain(testCoroutineDispatcher)
19 |
20 | base.evaluate()
21 |
22 | Dispatchers.resetMain()
23 | }
24 | }
25 |
26 | fun runTest(block: suspend TestScope.() -> Unit) = testScope.runTest { block() }
27 | }
28 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
18 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/app/src/main/java/com/rimapps/shoppingapp/features/wishList/repository/WishListDatabaseRepository.kt:
--------------------------------------------------------------------------------
1 | package com.rimapps.shoppingapp.features.wishList.repository
2 |
3 | import com.rimapps.shoppingapp.features.wishList.data.FavouriteProductEntity
4 | import com.rimapps.shoppingapp.features.wishList.dataBase.WishListDao
5 | import com.rimapps.shoppingapp.features.wishList.repository.WishListRepository
6 | import kotlinx.coroutines.Dispatchers
7 | import kotlinx.coroutines.withContext
8 | import javax.inject.Inject
9 |
10 |
11 | class WishListDatabaseRepository @Inject constructor(
12 | private val databaseDAO:WishListDao
13 | ) : WishListRepository {
14 |
15 | override suspend fun isFavourite(productId: String): Boolean {
16 | return withContext(Dispatchers.IO) {
17 | databaseDAO.isProductFavourite(productId) != null
18 | }
19 | }
20 |
21 | override suspend fun addToWishList(productId: String) {
22 | return withContext(Dispatchers.IO) {
23 | databaseDAO.addProductToFavourite(
24 | FavouriteProductEntity(productId,"")
25 | )
26 | }
27 | }
28 |
29 | override suspend fun removeFromWishList(productId: String) {
30 | return withContext(Dispatchers.IO) {
31 | databaseDAO.removeProductFromFavourite(
32 | FavouriteProductEntity(productId,"")
33 | )
34 | }
35 | }
36 |
37 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Kotlin code style for this project: "official" or "obsolete":
19 | kotlin.code.style=official
20 | # Enables namespacing of each library's R class so that its R class includes only the
21 | # resources declared in the library itself and none from the library's dependencies,
22 | # thereby reducing the size of the R class for that library
23 | android.nonTransitiveRClass=true
--------------------------------------------------------------------------------
/app/src/test/java/com/rimapps/shoppingapp/features/productList/presentation/ProductListViewStateTest.kt:
--------------------------------------------------------------------------------
1 | package com.rimapps.shoppingapp.features.productList.presentation
2 |
3 | import org.junit.Test
4 |
5 |
6 | class ProductListViewStateTest{
7 |
8 | @Test
9 | fun `Correct product viewState is updated when it is favourite`(){
10 | val content = ProductListViewState.Content(
11 | productList = (0..9).map{
12 | ProductCardViewState(
13 | it.toString(),
14 | "",
15 | "",
16 | "",
17 | "",
18 | false
19 |
20 | )
21 | }
22 | )
23 | val result = content.updateFavoriteProduct(
24 | "4",true
25 | )
26 | assert(result.productList[4].isFavourite)
27 |
28 | }
29 |
30 | @Test
31 | fun `Correct product ViewState is updated when it is not favourite`(){
32 | val content = ProductListViewState.Content(
33 | productList = (1..10).map {
34 | ProductCardViewState(
35 | it.toString(),
36 | "",
37 | "",
38 | "",
39 | "",
40 | false
41 | )
42 |
43 | }
44 | )
45 | val result = content.updateFavoriteProduct(
46 | "2",
47 | false
48 | )
49 |
50 | assert(!result.productList[2].isFavourite)
51 | }
52 | }
--------------------------------------------------------------------------------
/app/src/test/java/com/rimapps/shoppingapp/features/wishList/repository/WishListDatabaseRepositoryTest.kt:
--------------------------------------------------------------------------------
1 | package com.rimapps.shoppingapp.features.wishList.repository
2 |
3 | import com.rimapps.shoppingapp.features.wishList.data.FavouriteProductEntity
4 | import com.rimapps.shoppingapp.features.wishList.dataBase.WishListDao
5 | import io.mockk.coEvery
6 | import io.mockk.mockk
7 | import kotlinx.coroutines.ExperimentalCoroutinesApi
8 | import kotlinx.coroutines.test.runTest
9 | import org.junit.Before
10 | import org.junit.Test
11 |
12 | @OptIn(ExperimentalCoroutinesApi::class)
13 | class WishListDatabaseRepositoryTest{
14 |
15 | private lateinit var repository: WishListDatabaseRepository
16 | private var dao = mockk()
17 |
18 | @Before
19 | fun setup(){
20 | repository = WishListDatabaseRepository(dao)
21 | }
22 |
23 | @Test
24 | fun `when given product is saved in db it returns true`() = runTest{
25 | coEvery {
26 | dao.isProductFavourite("1")
27 | }returns FavouriteProductEntity(
28 | "1","banana"
29 | )
30 | assert(repository.isFavourite("1"))
31 | }
32 |
33 | @Test
34 | fun `when given product is not saved in db returns false`()= runTest {
35 |
36 | coEvery {
37 | dao.isProductFavourite("1")
38 | }returns null
39 |
40 | assert(!repository.isFavourite("1"))
41 | }
42 |
43 | @Test
44 | fun `when given product is save in db it returns true`() = runTest {
45 | coEvery {
46 | dao.isProductFavourite("1")
47 | }returns FavouriteProductEntity("1","banana")
48 | assert(repository.isFavourite("1"))
49 | }
50 |
51 |
52 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/rimapps/shoppingapp/features/productDetails/presentation/ProductDetailsViewModel.kt:
--------------------------------------------------------------------------------
1 | package com.rimapps.shoppingapp.features.productDetails.presentation
2 |
3 | import androidx.lifecycle.LiveData
4 | import androidx.lifecycle.MutableLiveData
5 | import androidx.lifecycle.ViewModel
6 | import androidx.lifecycle.viewModelScope
7 | import com.rimapps.shoppingapp.features.productDetails.business.ProductDetail
8 | import com.rimapps.shoppingapp.features.productList.presentation.ProductListViewState
9 | import com.rimapps.shoppingapp.shared.data.repository.ProductRepository
10 | import dagger.hilt.android.lifecycle.HiltViewModel
11 | import kotlinx.coroutines.CoroutineDispatcher
12 | import kotlinx.coroutines.Dispatchers
13 | import kotlinx.coroutines.flow.MutableStateFlow
14 | import kotlinx.coroutines.launch
15 | import javax.inject.Inject
16 |
17 | @HiltViewModel
18 | class ProductDetailsViewModel @Inject constructor(
19 | private val repository: ProductRepository
20 | ) : ViewModel() {
21 |
22 | private val _viewState = MutableStateFlow(ProductDetailsViewState.Loading)
23 | val viewState: MutableStateFlow
24 | get() = _viewState
25 |
26 | fun loadProduct(productId: String) {
27 | viewModelScope.launch {
28 | _viewState.value=ProductDetailsViewState.Loading
29 | // Data call to fetch products
30 | val productDetails = repository.getProductDetails(productId)
31 | _viewState.value=ProductDetailsViewState.Content(productDetails)
32 | }
33 | }
34 | }
--------------------------------------------------------------------------------
/app/src/test/java/com/rimapps/shoppingapp/features/wishList/usecase/AddOrRemoveFromWishListUseCaseTest.kt:
--------------------------------------------------------------------------------
1 | package com.rimapps.shoppingapp.features.wishList.usecase
2 |
3 | import com.rimapps.shoppingapp.features.wishList.repository.WishListRepository
4 | import io.mockk.coEvery
5 | import io.mockk.coVerify
6 | import io.mockk.mockk
7 | import kotlinx.coroutines.test.runTest
8 | import org.junit.Before
9 | import org.junit.Test
10 |
11 | class AddOrRemoveFromWishListUseCaseTest{
12 |
13 | private val isProductInWishListUseCase = mockk()
14 | private val wishListRepository = mockk(relaxed = true)
15 | private lateinit var useCase: AddOrRemoveFromWishListUseCase
16 |
17 | @Before
18 | fun setup(){
19 | useCase = AddOrRemoveFromWishListUseCase(
20 | wishListRepository,
21 | isProductInWishListUseCase
22 | )
23 | }
24 |
25 | @Test
26 | fun `product is not in wishlist and add method should work`() = runTest {
27 |
28 | coEvery {
29 | isProductInWishListUseCase.execute(any())
30 | }returns false
31 | useCase.execute("123")
32 |
33 | coVerify {
34 | wishListRepository.addToWishList("123")
35 | }
36 |
37 | }
38 | @Test
39 | fun `product is not in wishlist and remove method should work`() = runTest {
40 |
41 | coEvery {
42 | isProductInWishListUseCase.execute(any())
43 | }returns true
44 |
45 | useCase.execute("123")
46 |
47 | coVerify {
48 | wishListRepository.removeFromWishList("123")
49 | }
50 |
51 | }
52 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_product_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
17 |
18 |
27 |
37 |
38 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/app/src/main/java/com/rimapps/shoppingapp/shared/data/repository/api/ProductRepositoryApi.kt:
--------------------------------------------------------------------------------
1 | package com.rimapps.shoppingapp.shared.data.repository.api
2 |
3 | import com.rimapps.shoppingapp.features.productDetails.business.ProductDetail
4 | import com.rimapps.shoppingapp.features.productList.business.Product
5 | import com.rimapps.shoppingapp.features.productDetails.data.AsyncResult
6 | import com.rimapps.shoppingapp.shared.data.repository.ProductRepository
7 | import kotlinx.coroutines.Dispatchers
8 | import kotlinx.coroutines.withContext
9 | import javax.inject.Inject
10 |
11 | class ProductRepositoryApi @Inject constructor(private val service: ProductService) :
12 | ProductRepository {
13 |
14 | override suspend fun getProductList(): AsyncResult> {
15 | return withContext(Dispatchers.IO) {
16 | try {
17 | AsyncResult.Success(
18 | service.getProductList().map {
19 | Product(
20 | it.title,
21 | it.description,
22 | it.price,
23 | it.imageUrl,
24 | it.id
25 | )
26 | })
27 |
28 | }
29 | catch (exception:Exception){
30 | AsyncResult.Error(exception)
31 | }
32 | }
33 | }
34 | override suspend fun getProductDetails(productId: String): ProductDetail {
35 | return withContext(Dispatchers.IO){
36 | service.getProductDetails(productId).run {
37 | ProductDetail(
38 | this.title,
39 | this.description,
40 | this.full_description,
41 | "US $ ${this.price}",
42 | this.imageUrl,
43 | this.pros,
44 | this.cons
45 | )
46 | }
47 |
48 | }
49 | }
50 | }
--------------------------------------------------------------------------------
/app/src/test/java/com/rimapps/shoppingapp/shared/data/repository/api/ProductRepositoryApiTest.kt:
--------------------------------------------------------------------------------
1 | package com.rimapps.shoppingapp.shared.data.repository.api
2 | import com.rimapps.shoppingapp.features.productDetails.data.AsyncResult
3 | import com.rimapps.shoppingapp.features.productDetails.data.ProductDetailsEntity
4 | import com.rimapps.shoppingapp.features.productList.data.ProductEntity
5 | import io.mockk.coEvery
6 | import io.mockk.mockk
7 | import kotlinx.coroutines.ExperimentalCoroutinesApi
8 | import kotlinx.coroutines.test.runTest
9 | import org.junit.Before
10 | import org.junit.Test
11 |
12 | @ExperimentalCoroutinesApi
13 | class ProductRepositoryAPITest {
14 | private lateinit var repository: ProductRepositoryApi
15 | private val service = mockk()
16 |
17 | @Before
18 | fun setup() {
19 | repository = ProductRepositoryApi(service)
20 | }
21 |
22 | @Test
23 | fun `product entity correctly maps to business object`()= runTest {
24 |
25 | coEvery {
26 | service.getProductList()
27 |
28 | } returns (0..2).map {
29 | ProductEntity(
30 | it.toString(),
31 | "title $it",
32 | "price",
33 | 0.00,
34 | "",
35 | )
36 | }
37 |
38 | val result = repository.getProductList() as AsyncResult.Success
39 |
40 | assert(result.data.size==3)
41 | assert(result.data[1].title=="title 1")
42 |
43 | }
44 |
45 | @Test
46 | fun `repository correctly maps details to business objects`() = runTest{
47 | coEvery {
48 | service.getProductDetails("1")
49 | } returns ProductDetailsEntity(
50 | "Hello",
51 | "description",
52 | "full desc",
53 | 1.00,
54 | "",
55 | listOf(""),
56 | listOf(""),
57 | )
58 | val result = repository.getProductDetails("1")
59 | assert(result.title=="Hello")
60 |
61 |
62 |
63 | }
64 |
65 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/rimapps/shoppingapp/di/module/RepositoryModule.kt:
--------------------------------------------------------------------------------
1 | package com.rimapps.shoppingapp.di.module
2 |
3 | import android.content.Context
4 | import androidx.room.Room
5 | import com.rimapps.shoppingapp.features.wishList.repository.WishListDatabaseRepository
6 | import com.rimapps.shoppingapp.features.wishList.repository.WishListRepository
7 | import com.rimapps.shoppingapp.shared.data.repository.api.ApiClient
8 | import com.rimapps.shoppingapp.shared.data.repository.ProductRepository
9 | import com.rimapps.shoppingapp.shared.data.repository.api.ProductRepositoryApi
10 | import com.rimapps.shoppingapp.shared.data.repository.api.ProductService
11 | import com.rimapps.shoppingapp.features.wishList.dataBase.WishListDao
12 | import com.rimapps.shoppingapp.features.wishList.dataBase.WishListDatabase
13 | import dagger.Module
14 | import dagger.Provides
15 | import dagger.hilt.InstallIn
16 | import dagger.hilt.android.qualifiers.ApplicationContext
17 | import dagger.hilt.components.SingletonComponent
18 | import kotlinx.coroutines.CoroutineDispatcher
19 | import kotlinx.coroutines.Dispatchers
20 |
21 | @Module
22 | @InstallIn(SingletonComponent::class)
23 | class RepositoryModule {
24 |
25 | @Provides
26 | fun provideProductService(): ProductService = ApiClient.getService()
27 |
28 |
29 | @Provides
30 | fun providesProductRepositoryApi(
31 | service: ProductService
32 | ): ProductRepositoryApi = ProductRepositoryApi(service)
33 |
34 | @Provides
35 | fun providesProductRepository(
36 | productRepositoryAPI: ProductRepositoryApi
37 | ): ProductRepository = productRepositoryAPI
38 |
39 | @Provides
40 | fun providesWishListRepository(
41 | databaseRepository: WishListDatabaseRepository
42 | ): WishListRepository = databaseRepository
43 |
44 | @Provides
45 | fun providesWishListDAO(
46 | @ApplicationContext context: Context
47 | ): WishListDao {
48 | val db = Room.databaseBuilder(
49 | context, WishListDatabase::class.java,
50 | "shoppingApp-database"
51 | ).build()
52 | return db.wishListDao()
53 | }
54 | @Provides
55 | fun provideMainDispatcher(): CoroutineDispatcher = Dispatchers.Main
56 |
57 | }
58 |
59 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ShoppingApp
2 |
3 | **ShoppingApp** is a Kotlin-based Android application designed as a robust example of modern Android development practices. This project emphasizes the use of the MVVM (Model-View-ViewModel) architectural pattern, clean architecture concepts, and strict adherence to SOLID principles. It is ideal for developers who want to learn or demonstrate best practices in scalable, maintainable Android app development.
4 |
5 | ---
6 |
7 | ## Purpose
8 |
9 | The main goal of this project is to:
10 | - Showcase a clean separation of concerns using MVVM and clean architecture layers (presentation, domain, and data)
11 | - Illustrate the application of SOLID principles throughout the codebase
12 | - Serve as a learning and reference project for building scalable Android applications
13 |
14 | ---
15 |
16 | ## Features
17 |
18 | - Full MVVM architecture with clear ViewModel, Repository, and UseCase layers
19 | - Clean Architecture: Presentation, Domain, and Data modules
20 | - Strong adherence to SOLID principles for maintainable and testable code
21 | - Modular and testable components
22 | - Dependency injection (DI) ready (e.g., with Hilt/Dagger, if implemented)
23 | - Sample flows for product browsing, cart management, and checkout
24 | - Comprehensive use of Kotlin features and best practices
25 |
26 | ---
27 |
28 | ## Getting Started
29 |
30 | 1. **Clone the repository**
31 | ```bash
32 | git clone https://github.com/rimshadpcs/ShoppingApp.git
33 | ```
34 |
35 | 2. **Open in Android Studio**
36 | - Import the project as an existing Android Studio project.
37 | - Let Gradle sync and resolve dependencies.
38 |
39 | 3. **Build and Run**
40 | - Connect an Android device or start an emulator.
41 | - Build and install the app.
42 |
43 | ---
44 |
45 | ## Technologies & Concepts Used
46 |
47 | - **Kotlin**
48 | - **MVVM Architecture**
49 | - **Clean Architecture**
50 | - **SOLID Principles**
51 | - **Android Jetpack Components (LiveData, ViewModel, Navigation, etc.)**
52 | - **Coroutines/Flow**
53 | - **Dependency Injection** (if present, e.g., Hilt or Dagger)
54 | - **Repository and UseCase patterns**
55 | - **Unit & UI Testing (if present)**
56 |
57 | ---
58 |
59 | ## Project Structure
60 |
61 | ```
62 | /presentation - UI layer (Activities, Fragments, ViewModels)
63 | /domain - Business logic (UseCases, Entities, Repository interfaces)
64 | /data - Data sources (API, database, Repository implementations)
65 | ```
66 |
67 | ---
68 |
69 | ## Author
70 |
71 | - [rimshadpcs](https://github.com/rimshadpcs)
72 |
73 | ---
74 |
75 | ## License
76 |
77 | This project currently does not specify a license. Please contact the repository owner for more information.
78 |
79 | ---
80 |
81 | **Note:** This is a learning and reference project. For more details, review the code and comments throughout the repository.
--------------------------------------------------------------------------------
/app/src/main/java/com/rimapps/shoppingapp/features/productDetails/presentation/ProductDetailsFragment.kt:
--------------------------------------------------------------------------------
1 | package com.rimapps.shoppingapp.features.productDetails.presentation
2 |
3 | import android.os.Bundle
4 | import android.view.LayoutInflater
5 | import android.view.View
6 | import android.view.ViewGroup
7 | import androidx.core.view.isVisible
8 | import androidx.fragment.app.Fragment
9 | import androidx.fragment.app.viewModels
10 | import androidx.lifecycle.Lifecycle
11 | import androidx.lifecycle.flowWithLifecycle
12 | import androidx.lifecycle.lifecycleScope
13 | import com.bumptech.glide.Glide
14 | import com.rimapps.shoppingapp.R
15 | import com.rimapps.shoppingapp.databinding.FragmentProductDetailsBinding
16 | import dagger.hilt.android.AndroidEntryPoint
17 | import kotlinx.coroutines.launch
18 |
19 | @AndroidEntryPoint
20 | class ProductDetailsFragment : Fragment() {
21 | private lateinit var binding: FragmentProductDetailsBinding
22 | private val viewModel: ProductDetailsViewModel by viewModels()
23 |
24 | override fun onCreateView(
25 | inflater: LayoutInflater,
26 | container: ViewGroup?,
27 | savedInstanceState: Bundle?
28 | ): View? {
29 | binding = FragmentProductDetailsBinding.inflate(layoutInflater)
30 | return binding.root
31 | }
32 |
33 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
34 | super.onViewCreated(view, savedInstanceState)
35 | viewModel.loadProduct("someProductId")
36 | collectFromViewModel()
37 | }
38 |
39 | private fun collectFromViewModel() {
40 | viewLifecycleOwner.lifecycleScope.launch {
41 | viewModel.viewState.flowWithLifecycle(
42 | viewLifecycleOwner.lifecycle, Lifecycle.State.STARTED
43 | )
44 | .collect {
45 | updateUi(it)
46 | }
47 | }
48 | }
49 |
50 | private fun updateUi(viewState: ProductDetailsViewState) {
51 | when (viewState) {
52 | is ProductDetailsViewState.Content -> {
53 | with(binding) {
54 | binding.loadingView.isVisible = false
55 | val product = viewState.product
56 | viewProductTitle.text = product.title
57 | Glide.with(requireContext()).load(product.imageUrl)
58 | .into(viewProductImage)
59 | binding.viewPrice.text = product.price
60 | binding.viewFullDescription.text = product.fullDescription
61 | }
62 | }
63 |
64 | ProductDetailsViewState.Error -> {
65 | binding.loadingView.isVisible = false
66 | }
67 |
68 | ProductDetailsViewState.Loading -> {
69 | binding.loadingView.isVisible = true
70 | }
71 | }
72 | }
73 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/rimapps/shoppingapp/features/productList/presentation/ProductListViewModel.kt:
--------------------------------------------------------------------------------
1 | package com.rimapps.shoppingapp.features.productList.presentation
2 |
3 | import androidx.lifecycle.ViewModel
4 | import androidx.lifecycle.viewModelScope
5 | import com.rimapps.shoppingapp.features.productDetails.data.AsyncResult
6 | import com.rimapps.shoppingapp.shared.data.repository.ProductRepository
7 | import com.rimapps.shoppingapp.features.wishList.usecase.AddOrRemoveFromWishListUseCase
8 | import com.rimapps.shoppingapp.features.wishList.usecase.IsProductInWishListUseCase
9 | import dagger.hilt.android.lifecycle.HiltViewModel
10 | import kotlinx.coroutines.CoroutineDispatcher
11 | import kotlinx.coroutines.Dispatchers
12 | import kotlinx.coroutines.flow.Flow
13 | import kotlinx.coroutines.flow.MutableStateFlow
14 | import kotlinx.coroutines.launch
15 | import javax.inject.Inject
16 |
17 | @HiltViewModel
18 | class ProductListViewModel @Inject constructor(
19 | private val repository: ProductRepository,
20 | private val addOrRemoveFromWishListUseCase: AddOrRemoveFromWishListUseCase,
21 | private val isProductInWishListUseCase: IsProductInWishListUseCase,
22 | private val dispatcher: CoroutineDispatcher = Dispatchers.Main
23 |
24 | ) : ViewModel() {
25 |
26 | private val _viewState = MutableStateFlow(ProductListViewState.Loading)
27 | val viewState: Flow
28 | get() = _viewState
29 |
30 |
31 | fun loadProductList() {
32 | viewModelScope.launch(dispatcher) {
33 | _viewState.value = ProductListViewState.Loading
34 | // Data call to fetch products
35 | when (val productList = repository.getProductList()) {
36 | is AsyncResult.Error -> _viewState.value = ProductListViewState.Error
37 |
38 | is AsyncResult.Success ->
39 | _viewState.value = ProductListViewState.Content(productList.data.map {
40 | ProductCardViewState(
41 | it.productId,
42 | it.title,
43 | it.description,
44 | "US $ ${it.price}",
45 | it.imageUrl,
46 | isProductInWishListUseCase.execute(it.productId)
47 | )
48 | })
49 | }
50 | }
51 | }
52 |
53 | fun favouriteIconClicked(productId: String) {
54 | viewModelScope.launch(dispatcher) {
55 | addOrRemoveFromWishListUseCase.execute(productId)
56 | val currentViewState = _viewState.value
57 | (currentViewState as? ProductListViewState.Content)?.let { content ->
58 | _viewState.value
59 | content.updateFavoriteProduct(
60 | productId, isProductInWishListUseCase.execute(productId)
61 | )
62 | }
63 |
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.application'
3 | id 'org.jetbrains.kotlin.android'
4 | id 'kotlin-kapt'
5 | id 'com.google.dagger.hilt.android'
6 |
7 | }
8 | apply plugin: "androidx.navigation.safeargs"
9 | apply plugin: 'dagger.hilt.android.plugin'
10 |
11 |
12 | android {
13 | namespace 'com.rimapps.shoppingapp'
14 | compileSdk 33
15 |
16 | defaultConfig {
17 | applicationId "com.rimapps.shoppingapp"
18 | minSdk 24
19 | targetSdk 33
20 | versionCode 1
21 | versionName "1.0"
22 |
23 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
24 | }
25 |
26 | buildTypes {
27 | release {
28 | minifyEnabled false
29 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
30 | }
31 | }
32 | compileOptions {
33 | sourceCompatibility JavaVersion.VERSION_17
34 | targetCompatibility JavaVersion.VERSION_17
35 | }
36 | kotlinOptions {
37 | jvmTarget = '17'
38 | }
39 | android {
40 | viewBinding.enabled = true
41 | }
42 |
43 |
44 | }
45 |
46 | dependencies {
47 |
48 | implementation 'androidx.core:core-ktx:1.10.1'
49 | implementation 'androidx.appcompat:appcompat:1.6.1'
50 | implementation 'com.google.android.material:material:1.9.0'
51 | implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
52 | implementation 'androidx.navigation:navigation-fragment-ktx:2.5.3'
53 | implementation 'androidx.navigation:navigation-ui-ktx:2.5.3'
54 | testImplementation 'junit:junit:4.13.2'
55 | androidTestImplementation 'androidx.test.ext:junit:1.1.5'
56 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
57 |
58 | //Retrofit
59 | implementation 'com.squareup.retrofit2:retrofit:2.9.0'
60 | implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
61 | implementation 'com.squareup.okhttp3:okhttp:4.10.0'
62 |
63 | // Glide - Image loading
64 | implementation 'com.github.bumptech.glide:glide:4.14.2'
65 | annotationProcessor 'com.github.bumptech.glide:compiler:4.13.2'
66 |
67 | //lifecycle
68 | implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.6.1"
69 |
70 | //hilt
71 | implementation "com.google.dagger:hilt-android:2.44.2"
72 | kapt "com.google.dagger:hilt-compiler:2.44"
73 |
74 | //Room
75 | implementation "androidx.room:room-runtime:2.5.1"
76 | annotationProcessor "androidx.room:room-compiler:2.5.1"
77 | kapt "androidx.room:room-compiler:2.5.1"
78 |
79 | // Mockk
80 | testImplementation "io.mockk:mockk:1.12.1"
81 | testImplementation "androidx.arch.core:core-testing:2.2.0"
82 | // Coroutines Test
83 | testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4'
84 | testImplementation "androidx.arch.core:core-testing:2.2.0"
85 | implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.6.1"
86 | }
87 | kapt {
88 | correctErrorTypes true
89 | }
90 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/app/src/main/java/com/rimapps/shoppingapp/features/productList/presentation/ProductCardListAdapter.kt:
--------------------------------------------------------------------------------
1 | package com.rimapps.shoppingapp.features.productList.presentation
2 |
3 | import android.annotation.SuppressLint
4 | import android.view.LayoutInflater
5 | import android.view.View
6 | import android.view.ViewGroup
7 | import androidx.core.content.res.ResourcesCompat
8 | import androidx.recyclerview.widget.RecyclerView
9 | import com.bumptech.glide.Glide
10 | import com.bumptech.glide.request.target.BitmapImageViewTarget
11 | import com.rimapps.shoppingapp.R
12 | import com.rimapps.shoppingapp.databinding.ProductCardBinding
13 | class ProductCardListAdapter(
14 | val onItemClicked: (ProductCardViewState) -> Unit,
15 | val onFavoriteIconClicked: (ProductCardViewState) -> Unit,
16 |
17 | ) : RecyclerView.Adapter() {
18 |
19 |
20 | private var data: List = emptyList()
21 |
22 | override fun onCreateViewHolder(
23 | parent: ViewGroup,
24 | viewType: Int
25 | ): ViewHolder {
26 | return ViewHolder(
27 | LayoutInflater.from(parent.context).inflate(R.layout.product_card, parent, false)
28 | )
29 | }
30 |
31 | override fun onBindViewHolder(holder: ViewHolder, position: Int) {
32 | holder.bind(data[position])
33 | }
34 |
35 | override fun getItemCount(): Int {
36 | return data.size
37 | }
38 |
39 | @SuppressLint("NotifyDataSetChanged")
40 | fun setData(productList: List) {
41 | this.data = productList
42 | notifyDataSetChanged()
43 | }
44 |
45 | inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
46 | fun bind(productCardViewState: ProductCardViewState) {
47 | val bind = ProductCardBinding.bind(itemView)
48 | itemView.setOnClickListener {
49 | onItemClicked(productCardViewState)
50 | }
51 | bind.apply {
52 | viewProductName.text = productCardViewState.title
53 | viewProductDescription.text = productCardViewState.description
54 | productPrice.text = productCardViewState.price
55 |
56 | viewWishlistIcon.setOnClickListener {
57 | onFavoriteIconClicked.invoke(
58 | productCardViewState
59 | )
60 | }
61 |
62 | viewWishlistIcon.setImageDrawable(
63 | if(productCardViewState.isFavourite){
64 | ResourcesCompat.getDrawable(viewWishlistIcon.resources,R.drawable.ic_favourite_enabled,null)
65 |
66 | }else{
67 | ResourcesCompat.getDrawable(viewWishlistIcon.resources,R.drawable.ic_favourite_disabled,null)
68 | }
69 | )
70 | Glide.with(productImage)
71 | .asBitmap()
72 | .load(productCardViewState.imageUrl)
73 | .into(BitmapImageViewTarget(productImage))
74 | }
75 | }
76 |
77 | }
78 | }
--------------------------------------------------------------------------------
/app/src/test/java/com/rimapps/shoppingapp/features/productList/presentation/ProductListViewModelTest.kt:
--------------------------------------------------------------------------------
1 | package com.rimapps.shoppingapp.features.productList.presentation
2 |
3 | import com.rimapps.shoppingapp.TestCoroutineRule
4 | import com.rimapps.shoppingapp.features.productDetails.data.AsyncResult
5 | import com.rimapps.shoppingapp.features.productList.business.Product
6 | import com.rimapps.shoppingapp.features.wishList.usecase.AddOrRemoveFromWishListUseCase
7 | import com.rimapps.shoppingapp.features.wishList.usecase.IsProductInWishListUseCase
8 | import com.rimapps.shoppingapp.shared.data.repository.ProductRepository
9 | import io.mockk.coEvery
10 | import io.mockk.mockk
11 | import kotlinx.coroutines.ExperimentalCoroutinesApi
12 | import kotlinx.coroutines.flow.first
13 | import kotlinx.coroutines.launch
14 | import kotlinx.coroutines.test.StandardTestDispatcher
15 | import kotlinx.coroutines.test.runTest
16 | import org.junit.Assert
17 | import org.junit.Before
18 | import org.junit.Rule
19 | import org.junit.Test
20 |
21 | @OptIn(ExperimentalCoroutinesApi::class)
22 | class ProductListViewModelTest {
23 |
24 | @get:Rule
25 | var testRule = TestCoroutineRule()
26 | private val dispatcher = StandardTestDispatcher()
27 |
28 | private lateinit var viewModel: ProductListViewModel
29 | private val repository = mockk()
30 | private val addOrRemoveFromWishListUseCase = mockk()
31 | private val isProductInWishListUseCase = mockk()
32 | private val listOfProducts = (0..2).map {
33 | Product("title", "description", 6.0, "", "id-$it")
34 | }
35 |
36 | private val lisOfProductCardList = (0..2).map {
37 | ProductCardViewState(it.toString(), "title", "desc", "3.0", "", false)
38 | }
39 |
40 | @Before
41 | fun setup() {
42 | coEvery { isProductInWishListUseCase.execute(any()) } returns false
43 | coEvery {
44 | isProductInWishListUseCase.execute("id-1")
45 | } returns true
46 | coEvery {
47 | repository.getProductList()
48 | } returns AsyncResult.Success(listOfProducts)
49 |
50 | viewModel = ProductListViewModel(
51 | repository,
52 | addOrRemoveFromWishListUseCase,
53 | isProductInWishListUseCase,
54 | dispatcher
55 | )
56 | }
57 |
58 | //This test working fine
59 | @Test
60 | fun `initial state is Loading`() = testRule.runTest {
61 | val viewModel = ProductListViewModel(
62 | repository,
63 | addOrRemoveFromWishListUseCase,
64 | isProductInWishListUseCase,
65 | dispatcher
66 | )
67 |
68 | val actualState = viewModel.viewState.first()
69 |
70 | Assert.assertEquals(ProductListViewState.Loading, actualState)
71 | }
72 |
73 | //Not working
74 | @Test
75 | fun `Load method correctly when creates the viewState`() = runTest {
76 | val values = mutableListOf()
77 |
78 | val job = launch {
79 | viewModel.viewState.collect {
80 |
81 | values.add(it)
82 | }
83 |
84 | viewModel.loadProductList()
85 | dispatcher.scheduler.advanceUntilIdle()
86 | assert(values[1] ==
87 | ProductListViewState.Content(
88 | (0..2).map {
89 | ProductCardViewState(
90 | "id-$it",
91 | "title",
92 | "description",
93 | "US $ 6.0",
94 | "",
95 | it == 1
96 | )
97 | }
98 | ))
99 |
100 | }
101 | job.cancel()
102 | }
103 | }
104 |
105 |
--------------------------------------------------------------------------------
/app/src/main/java/com/rimapps/shoppingapp/features/productList/presentation/ProductListFragment.kt:
--------------------------------------------------------------------------------
1 | package com.rimapps.shoppingapp.features.productList.presentation
2 |
3 | import android.os.Bundle
4 | import androidx.fragment.app.Fragment
5 | import android.view.LayoutInflater
6 | import android.view.View
7 | import android.view.ViewGroup
8 | import android.widget.Toast
9 | import androidx.core.view.isVisible
10 | import androidx.fragment.app.viewModels
11 | import androidx.lifecycle.Lifecycle
12 | import androidx.lifecycle.flowWithLifecycle
13 | import androidx.lifecycle.lifecycleScope
14 | import androidx.navigation.fragment.findNavController
15 | import androidx.recyclerview.widget.LinearLayoutManager
16 | import com.rimapps.shoppingapp.databinding.FragmentProductListBinding
17 | import dagger.hilt.android.AndroidEntryPoint
18 | import kotlinx.coroutines.launch
19 | import okhttp3.internal.notify
20 | import okhttp3.internal.notifyAll
21 |
22 | @AndroidEntryPoint
23 | class ProductListFragment : Fragment() {
24 | private lateinit var binding: FragmentProductListBinding
25 | private val viewModel: ProductListViewModel by viewModels()
26 | private val adapter = ProductCardListAdapter(
27 | ::onItemClicked,
28 | ::onFavouriteIconClicked
29 | )
30 |
31 |
32 | override fun onCreateView(
33 | inflater: LayoutInflater,
34 | container: ViewGroup?,
35 | savedInstanceState: Bundle?
36 | ): View? {
37 | binding = FragmentProductListBinding.inflate(layoutInflater)
38 | return binding.root
39 | }
40 |
41 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
42 | super.onViewCreated(view, savedInstanceState)
43 |
44 | setViews()
45 |
46 | collectFromViewModel()
47 | viewModel.loadProductList()
48 | viewModel.viewState
49 | }
50 |
51 | private fun setViews() {
52 | binding.viewProductList.layoutManager =
53 | LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false)
54 | binding.viewProductList.adapter = adapter
55 | }
56 |
57 | private fun collectFromViewModel() {
58 | viewLifecycleOwner.lifecycleScope.launch {
59 | viewModel.viewState.flowWithLifecycle(
60 | viewLifecycleOwner.lifecycle,
61 | Lifecycle.State.STARTED
62 | ).collect {
63 | updateUI(it)
64 | }
65 | }
66 | }
67 |
68 |
69 | private fun updateUI(viewState: ProductListViewState) {
70 | when(viewState){
71 | is ProductListViewState.Content -> {
72 | binding.viewProductList.isVisible = true
73 | binding.errorView.isVisible = false
74 | binding.loadingView.isVisible = false
75 | adapter.setData(viewState.productList)
76 | }
77 |
78 | ProductListViewState.Error -> {
79 | binding.viewProductList.isVisible = false
80 | binding.errorView.isVisible = true
81 | binding.loadingView.isVisible = false
82 | }
83 |
84 | ProductListViewState.Loading -> {
85 | binding.viewProductList.isVisible = false
86 | binding.errorView.isVisible = false
87 | binding.loadingView.isVisible = true
88 | }
89 | }
90 | }
91 |
92 | // parameter just to show how to retrieve data from Adapter to the fragment
93 | private fun onItemClicked(viewState: ProductCardViewState) {
94 | findNavController().navigate(ProductListFragmentDirections.actionProductListFragmentToProductDetailsFragment())
95 | }
96 |
97 | private fun onFavouriteIconClicked(productCardViewState: ProductCardViewState) {
98 | viewModel.favouriteIconClicked(productCardViewState.id)
99 | }
100 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_product_details.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
17 |
18 |
29 |
30 |
40 |
41 |
42 |
54 |
55 |
66 |
67 |
78 |
79 |
88 |
89 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/product_card.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
13 |
14 |
24 |
25 |
35 |
36 |
46 |
47 |
48 |
62 |
73 |
74 |
88 |
89 |
90 |
91 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | ##
21 | ## Gradle start up script for UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 |
86 | # Determine the Java command to use to start the JVM.
87 | if [ -n "$JAVA_HOME" ] ; then
88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
89 | # IBM's JDK on AIX uses strange locations for the executables
90 | JAVACMD="$JAVA_HOME/jre/sh/java"
91 | else
92 | JAVACMD="$JAVA_HOME/bin/java"
93 | fi
94 | if [ ! -x "$JAVACMD" ] ; then
95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
96 |
97 | Please set the JAVA_HOME variable in your environment to match the
98 | location of your Java installation."
99 | fi
100 | else
101 | JAVACMD="java"
102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
103 |
104 | Please set the JAVA_HOME variable in your environment to match the
105 | location of your Java installation."
106 | fi
107 |
108 | # Increase the maximum file descriptors if we can.
109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
110 | MAX_FD_LIMIT=`ulimit -H -n`
111 | if [ $? -eq 0 ] ; then
112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
113 | MAX_FD="$MAX_FD_LIMIT"
114 | fi
115 | ulimit -n $MAX_FD
116 | if [ $? -ne 0 ] ; then
117 | warn "Could not set maximum file descriptor limit: $MAX_FD"
118 | fi
119 | else
120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
121 | fi
122 | fi
123 |
124 | # For Darwin, add options to specify how the application appears in the dock
125 | if $darwin; then
126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
127 | fi
128 |
129 | # For Cygwin or MSYS, switch paths to Windows format before running java
130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133 |
134 | JAVACMD=`cygpath --unix "$JAVACMD"`
135 |
136 | # We build the pattern for arguments to be converted via cygpath
137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
138 | SEP=""
139 | for dir in $ROOTDIRSRAW ; do
140 | ROOTDIRS="$ROOTDIRS$SEP$dir"
141 | SEP="|"
142 | done
143 | OURCYGPATTERN="(^($ROOTDIRS))"
144 | # Add a user-defined pattern to the cygpath arguments
145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
147 | fi
148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
149 | i=0
150 | for arg in "$@" ; do
151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
153 |
154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
156 | else
157 | eval `echo args$i`="\"$arg\""
158 | fi
159 | i=`expr $i + 1`
160 | done
161 | case $i in
162 | 0) set -- ;;
163 | 1) set -- "$args0" ;;
164 | 2) set -- "$args0" "$args1" ;;
165 | 3) set -- "$args0" "$args1" "$args2" ;;
166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
172 | esac
173 | fi
174 |
175 | # Escape application args
176 | save () {
177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
178 | echo " "
179 | }
180 | APP_ARGS=`save "$@"`
181 |
182 | # Collect all arguments for the java command, following the shell quoting and substitution rules
183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
184 |
185 | exec "$JAVACMD" "$@"
186 |
--------------------------------------------------------------------------------