Skip to content

Commit

Permalink
Prepping new feature: persisting data in database
Browse files Browse the repository at this point in the history
  • Loading branch information
Nnamodi committed Jul 18, 2024
1 parent f3e03ba commit 293da80
Show file tree
Hide file tree
Showing 85 changed files with 1,031 additions and 189 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ dependencies {
implementation(libs.koin.core)

// other modules
implementation(project(path = ":domain"))
implementation(project(path = ":localDataSource"))
implementation(project(path = ":remoteDataSource"))

// test
Expand Down
9 changes: 8 additions & 1 deletion app/src/main/java/com/roland/android/destore/DeStoreApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import com.roland.android.destore.ui.screen.cart.CartViewModel
import com.roland.android.destore.ui.screen.details.DetailsViewModel
import com.roland.android.destore.ui.screen.home.HomeViewModel
import com.roland.android.destore.ui.screen.list.ListViewModel
import com.roland.android.domain.di.DomainModule.domainModule
import com.roland.android.localdatasource.di.PersistenceModule.persistenceModule
import com.roland.android.remotedatasource.di.NetworkModule.remoteDataModule
import org.koin.android.ext.koin.androidContext
import org.koin.android.ext.koin.androidLogger
Expand All @@ -20,7 +22,12 @@ class DeStoreApp : Application() {
startKoin {
androidContext(this@DeStoreApp)
androidLogger(Level.INFO)
modules(appModule, remoteDataModule)
modules(
appModule,
domainModule,
persistenceModule,
remoteDataModule
)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.roland.android.destore.data

import com.roland.android.remotedatasource.usecase.data.CartItem
import com.roland.android.remotedatasource.usecase.data.Item
import com.roland.android.domain.data.CartItem
import com.roland.android.domain.data.Item
import kotlinx.coroutines.flow.MutableStateFlow

val cartItemsFlow: MutableStateFlow<List<CartItem>> = MutableStateFlow(emptyList())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ import com.roland.android.destore.R
import com.roland.android.destore.utils.Extensions.getColor
import com.roland.android.destore.utils.Extensions.round
import com.roland.android.destore.utils.painterPlaceholder
import com.roland.android.remotedatasource.usecase.data.CartItem
import com.roland.android.remotedatasource.usecase.data.Item
import com.roland.android.domain.data.CartItem
import com.roland.android.domain.data.Item
import com.roland.android.remotedatasource.utils.Constant.BASE_IMAGE_URL

typealias ItemId = String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.roland.android.destore.R
import com.roland.android.destore.data.UserInfo
import com.roland.android.domain.data.UserInfo
import com.roland.android.destore.ui.theme.SkyBlue
import com.roland.android.destore.utils.Extensions.round
import com.roland.android.destore.utils.Extensions.transformList
import com.roland.android.remotedatasource.usecase.data.CartItem
import com.roland.android.remotedatasource.usecase.data.Item
import com.roland.android.domain.data.CartItem
import com.roland.android.domain.data.Item
import kotlinx.coroutines.launch

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.unit.dp
import com.roland.android.remotedatasource.utils.Constant.errorMessage
import com.roland.android.remotedatasource.utils.State
import com.roland.android.domain.data.State

@Composable
fun <T: Any>CommonScreen(
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.roland.android.destore.ui.screen.cart

import com.roland.android.remotedatasource.usecase.data.CartItem
import com.roland.android.domain.data.CartItem

sealed class CartActions {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import com.roland.android.destore.ui.navigation.Screens
import com.roland.android.destore.ui.screen.EmptyScreen
import com.roland.android.destore.ui.theme.DeStoreTheme
import com.roland.android.destore.utils.Extensions.round
import com.roland.android.remotedatasource.usecase.data.CartItem
import com.roland.android.domain.data.CartItem

@Composable
fun CartScreen(
Expand Down Expand Up @@ -64,7 +64,12 @@ fun CartScreen(
@Composable
private fun CartScreenPreview() {
DeStoreTheme {
val uiState = CartUiState(listOf(CartItem(), CartItem(), CartItem(), CartItem()))
val uiState = CartUiState(listOf(
CartItem(),
CartItem(),
CartItem(),
CartItem()
))
CartScreen(uiState, {}) {}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.roland.android.destore.ui.screen.cart

import com.roland.android.remotedatasource.usecase.data.CartItem
import com.roland.android.domain.data.CartItem

data class CartUiState(
val cartItems: List<CartItem> = emptyList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import androidx.lifecycle.viewModelScope
import com.roland.android.destore.data.cartItemsFlow
import com.roland.android.destore.ui.screen.checkout.CheckoutUiState
import com.roland.android.destore.utils.Extensions.filterCartItems
import com.roland.android.remotedatasource.usecase.data.CartItem
import com.roland.android.domain.data.CartItem
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.update
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import com.roland.android.destore.ui.navigation.AppRoute
import com.roland.android.destore.ui.navigation.Screens
import com.roland.android.destore.ui.screen.cart.CartActions
import com.roland.android.destore.ui.theme.DeStoreTheme
import com.roland.android.remotedatasource.usecase.data.CartItem
import com.roland.android.domain.data.CartItem

@Composable
fun CheckoutScreen(
Expand Down Expand Up @@ -55,7 +55,12 @@ fun CheckoutScreen(
@Composable
private fun CheckoutScreenPreview() {
DeStoreTheme {
val uiState = CheckoutUiState(listOf(CartItem(), CartItem(), CartItem(), CartItem()))
val uiState = CheckoutUiState(listOf(
CartItem(),
CartItem(),
CartItem(),
CartItem()
))
CheckoutScreen(uiState, {}) {}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.roland.android.destore.ui.screen.checkout

import com.roland.android.destore.data.UserInfo
import com.roland.android.remotedatasource.usecase.data.CartItem
import com.roland.android.domain.data.UserInfo
import com.roland.android.domain.data.CartItem

data class CheckoutUiState(
val cartItems: List<CartItem> = emptyList(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.roland.android.destore.ui.screen.details

import com.roland.android.remotedatasource.usecase.data.Item
import com.roland.android.domain.data.Item

sealed class DetailsActions {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ import com.roland.android.destore.ui.theme.DeStoreTheme
import com.roland.android.destore.ui.theme.Grey
import com.roland.android.destore.ui.theme.SkyBlue
import com.roland.android.destore.utils.Extensions.toItem
import com.roland.android.remotedatasource.usecase.data.ItemDetails
import com.roland.android.remotedatasource.utils.State
import com.roland.android.domain.data.ItemDetails
import com.roland.android.domain.data.State
import kotlinx.coroutines.launch
import kotlin.math.min

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.roland.android.destore.ui.screen.details

import com.roland.android.remotedatasource.usecase.data.Item
import com.roland.android.remotedatasource.usecase.data.ItemDetails
import com.roland.android.remotedatasource.utils.State
import com.roland.android.domain.data.Item
import com.roland.android.domain.data.ItemDetails
import com.roland.android.domain.data.State

data class DetailsUiState(
val details: State<ItemDetails>? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import com.roland.android.destore.utils.Extensions.filterCartItems
import com.roland.android.destore.utils.Extensions.toCartItem
import com.roland.android.destore.utils.ResponseConverter.convertToCategoryData
import com.roland.android.destore.utils.ResponseConverter.convertToDetailsData
import com.roland.android.remotedatasource.usecase.GetCategoryUseCase
import com.roland.android.remotedatasource.usecase.GetProductUseCase
import com.roland.android.remotedatasource.usecase.data.CartItem
import com.roland.android.remotedatasource.usecase.data.Item
import com.roland.android.remotedatasource.utils.State
import com.roland.android.domain.usecase.GetCategoryUseCase
import com.roland.android.domain.usecase.GetProductUseCase
import com.roland.android.domain.data.CartItem
import com.roland.android.domain.data.Item
import com.roland.android.domain.data.State
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.update
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.roland.android.destore.ui.screen.home

import com.roland.android.remotedatasource.usecase.data.Item
import com.roland.android.domain.data.Item

sealed class HomeActions {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ import com.roland.android.destore.ui.theme.Red
import com.roland.android.destore.ui.theme.SkyBlue
import com.roland.android.destore.utils.Extensions.greetings
import com.roland.android.destore.utils.Extensions.transformList
import com.roland.android.remotedatasource.usecase.data.Item
import com.roland.android.remotedatasource.utils.Constant.ADDIDAS_CATEGORY
import com.roland.android.remotedatasource.utils.Constant.FEATURED_CATEGORY
import com.roland.android.remotedatasource.utils.Constant.NIKE_CATEGORY
import com.roland.android.remotedatasource.utils.Constant.REEBOK_CATEGORY
import com.roland.android.remotedatasource.utils.Constant.TIMBERLAND_CATEGORY
import com.roland.android.remotedatasource.utils.State
import com.roland.android.domain.data.Item
import com.roland.android.domain.Constant.ADDIDAS_CATEGORY
import com.roland.android.domain.Constant.FEATURED_CATEGORY
import com.roland.android.domain.Constant.NIKE_CATEGORY
import com.roland.android.domain.Constant.REEBOK_CATEGORY
import com.roland.android.domain.Constant.TIMBERLAND_CATEGORY
import com.roland.android.domain.data.State
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlin.math.absoluteValue
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.roland.android.destore.ui.screen.home

import com.roland.android.remotedatasource.usecase.data.Item
import com.roland.android.remotedatasource.utils.State
import com.roland.android.domain.data.Item
import com.roland.android.domain.data.State

data class HomeUiState(
val data: State<HomeDataModel>? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import com.roland.android.destore.ui.components.Colors
import com.roland.android.destore.ui.screen.details.Sizes
import com.roland.android.destore.utils.Extensions.toCartItem
import com.roland.android.destore.utils.ResponseConverter.convertToHomeData
import com.roland.android.remotedatasource.usecase.GetProductsUseCase
import com.roland.android.remotedatasource.usecase.data.CartItem
import com.roland.android.remotedatasource.usecase.data.Item
import com.roland.android.domain.usecase.GetProductsUseCase
import com.roland.android.domain.data.CartItem
import com.roland.android.domain.data.Item
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.update
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.roland.android.destore.ui.screen.list

import com.roland.android.remotedatasource.usecase.data.Item
import com.roland.android.domain.data.Item

sealed class ListActions {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import com.roland.android.destore.ui.screen.LoadingScreen
import com.roland.android.destore.ui.screen.details.Sizes
import com.roland.android.destore.ui.screen.list.ListActions.Favorite
import com.roland.android.destore.ui.theme.DeStoreTheme
import com.roland.android.remotedatasource.utils.State
import com.roland.android.domain.data.State

@Composable
fun ListScreen(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.roland.android.destore.ui.screen.list

import com.roland.android.remotedatasource.usecase.data.Item
import com.roland.android.remotedatasource.utils.State
import com.roland.android.domain.data.Item
import com.roland.android.domain.data.State

data class ListUiState(
val data: State<List<Item>>? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import com.roland.android.destore.data.cartItemsFlow
import com.roland.android.destore.data.favoriteItemsFlow
import com.roland.android.destore.utils.Extensions.toCartItem
import com.roland.android.destore.utils.ResponseConverter.convertToCategoryData
import com.roland.android.remotedatasource.usecase.GetCategoryUseCase
import com.roland.android.remotedatasource.usecase.data.CartItem
import com.roland.android.remotedatasource.usecase.data.Item
import com.roland.android.remotedatasource.utils.State
import com.roland.android.domain.usecase.GetCategoryUseCase
import com.roland.android.domain.data.CartItem
import com.roland.android.domain.data.Item
import com.roland.android.domain.data.State
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.update
Expand Down
24 changes: 13 additions & 11 deletions app/src/main/java/com/roland/android/destore/utils/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package com.roland.android.destore.utils
import android.content.Context
import com.roland.android.destore.R
import com.roland.android.destore.ui.components.Colors
import com.roland.android.remotedatasource.usecase.data.CartItem
import com.roland.android.remotedatasource.usecase.data.Category
import com.roland.android.remotedatasource.usecase.data.Item
import com.roland.android.remotedatasource.usecase.data.ItemDetails
import com.roland.android.domain.data.CartItem
import com.roland.android.domain.data.Category
import com.roland.android.domain.data.Item
import com.roland.android.domain.data.ItemDetails
import java.math.BigDecimal
import java.math.RoundingMode
import java.util.Calendar
Expand Down Expand Up @@ -34,13 +34,15 @@ object Extensions {
return Colors.valueOf(color?.name ?: Colors.ColorBlue.name)
}

fun ItemDetails.toItem(price: String) = Item(
id = id,
name = name,
photos = photos,
currentPrice = price,
category = categories.firstOrNull() ?: Category(name = "Generic")
)
fun ItemDetails.toItem(price: String) =
Item(
id = id,
name = name,
photos = photos,
currentPrice = price,
category = categories.firstOrNull()
?: Category(name = "Generic")
)

fun Item.toCartItem(
color: Long,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.roland.android.destore.utils

import com.roland.android.destore.ui.screen.home.HomeDataModel
import com.roland.android.remotedatasource.usecase.GetCategoryUseCase
import com.roland.android.remotedatasource.usecase.GetProductUseCase
import com.roland.android.remotedatasource.usecase.GetProductsUseCase
import com.roland.android.remotedatasource.usecase.data.Item
import com.roland.android.remotedatasource.usecase.data.ItemDetails
import com.roland.android.remotedatasource.utils.State
import com.roland.android.domain.usecase.GetCategoryUseCase
import com.roland.android.domain.usecase.GetProductUseCase
import com.roland.android.domain.usecase.GetProductsUseCase
import com.roland.android.domain.data.Item
import com.roland.android.domain.data.ItemDetails
import com.roland.android.domain.data.State

object ResponseConverter {

Expand Down
Loading

0 comments on commit 293da80

Please sign in to comment.