Skip to content

Commit

Permalink
[MERGE/#127] pulled develop
Browse files Browse the repository at this point in the history
  • Loading branch information
boiledEgg-s committed Jan 24, 2025
2 parents 1daf8b6 + 14272b0 commit 25bc3e8
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 67 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package com.napzak.market.core.designsystem.component

import android.os.Build
import android.view.View
import android.view.Window
import androidx.activity.ComponentActivity
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
Expand All @@ -24,60 +20,39 @@ import com.napzak.market.core.designsystem.theme.NapzakMarketTheme

@Composable
fun LoadingScreen(
modifier: Modifier = Modifier
isLoading: Boolean,
modifier: Modifier = Modifier,
isLightTheme: Boolean = false,
) {
val view by rememberUpdatedState(LocalView.current)
val window = remember { (view.context as? ComponentActivity)?.window }
val backgroudColor = NapzakMarketTheme.colors.black70
val originalColor = NapzakMarketTheme.colors.white
val loadingColor = NapzakMarketTheme.colors.black70

LaunchedEffect(key1 = Unit) {
LaunchedEffect(isLoading) {
window?.let {
setSystemBarStyle(
window = window,
view = view,
isLightTheme = false,
barColor = backgroudColor.toArgb(),
)
}
}
val statusBarColor = if (isLoading) loadingColor else originalColor
val navigationBarColor = if (isLoading) loadingColor else originalColor

DisposableEffect(key1 = Unit) {
onDispose {
setSystemBarStyle(
window = window,
view = view,
isLightTheme = true,
barColor = backgroudColor.toArgb(),
)
}
}
it.statusBarColor = statusBarColor.toArgb()
it.navigationBarColor = navigationBarColor.toArgb()

Box(
modifier = modifier
.fillMaxSize()
.background(backgroudColor),
contentAlignment = Alignment.Center
) {
CircularProgressIndicator(
color = NapzakMarketTheme.colors.purple30
)
val controller = WindowCompat.getInsetsController(it, view)
controller.isAppearanceLightStatusBars = !isLoading
controller.isAppearanceLightNavigationBars = !isLoading
}
}
}

private fun setSystemBarStyle(
window: Window?,
view: View,
isLightTheme: Boolean,
barColor: Int,
) {
window?.let {
val controller = WindowCompat.getInsetsController(it, view)
controller.isAppearanceLightStatusBars = isLightTheme
controller.isAppearanceLightNavigationBars = isLightTheme

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.VANILLA_ICE_CREAM) {
it.statusBarColor = barColor
it.navigationBarColor = barColor
if (isLoading) {
Box(
modifier = modifier
.fillMaxSize()
.background(loadingColor),
contentAlignment = Alignment.Center
) {
CircularProgressIndicator(
color = NapzakMarketTheme.colors.purple30
)
}
}
}
Expand All @@ -86,6 +61,9 @@ private fun setSystemBarStyle(
@Composable
private fun LoadingScreenPreview() {
NapzakMarketTheme {
LoadingScreen()
LoadingScreen(
isLoading = true,
isLightTheme = true
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,22 @@ fun ProductImage.toProductPhotoDto() = ProductPhotoDto(
fun BuyProduct.toBuyRegistrationRequestDto() = ProductBuyRegistrationRequestDto(
productPhotoDto = imageUrls.map { it.toProductPhotoDto() },
genreId = genreId,
title = title,
title = title.trim(),
description = description,
price = price * 1000,
price = price * THOUSAND,
isPriceNegotiable = isPriceNegotiable,
)

fun SellProduct.toSellRegistrationRequestDto() = ProductSellRegistrationRequestDto(
productPhotoDto = imageUrls.map { it.toProductPhotoDto() },
genreId = genreId,
title = title,
title = title.trim(),
description = description,
price = price,
productCondition = fromCondition(productCondition),
isDeliveryIncluded = isDeliveryIncluded,
standardDeliveryFee = standardDeliveryFee,
halfDeliveryFee = halfDeliveryFee,
)

private const val THOUSAND = 1_000
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ fun MainRegisterDialog(
modifier = modifier
.width(IntrinsicSize.Max)
.clip(RoundedCornerShape(12.dp))
.background(color = NapzakMarketTheme.colors.white)
.padding(vertical = 16.dp),
verticalArrangement = Arrangement.spacedBy(16.dp),
.background(color = NapzakMarketTheme.colors.white),
) {
RegisterTab.entries.forEachIndexed { index, tab ->
val onClick = when (tab) {
Expand All @@ -111,7 +109,6 @@ fun MainRegisterDialog(
image = ImageVector.vectorResource(tab.iconRes),
label = stringResource(tab.titleRes),
onClick = onClick,
modifier = Modifier.padding(horizontal = 26.dp)
)

if (index != RegisterTab.entries.lastIndex) {
Expand All @@ -135,6 +132,7 @@ private fun RegisterNavigationButton(
Row(
modifier = Modifier
.noRippleClickable(onClick)
.padding(horizontal = 26.dp, vertical = 16.dp)
.then(modifier),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(8.dp),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,9 @@ fun RegistrationScreen(
modifier = modifier.fillMaxSize(),
) {
LazyColumn(
modifier = modifier.background(NapzakMarketTheme.colors.white),
modifier = modifier
.fillMaxSize()
.background(NapzakMarketTheme.colors.white),
state = listState,
) {
stickyHeader {
Expand Down Expand Up @@ -333,9 +335,9 @@ fun RegistrationScreen(
)
}
}
if (uiState.loadState == UiState.Loading) {
LoadingScreen()
}
LoadingScreen(
isLoading = uiState.loadState == UiState.Loading,
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class RegistrationViewModel @Inject constructor(
) {
when (inputType) {
is NumeralInputType.ProductPurchasePrice -> _uiState.update { currentState ->
currentState.copy(productPurchasePrice = formatPriceValue(newValue, MAX_PURCHASE_PRICE))
currentState.copy(productPurchasePrice = formatPriceValue(newValue, MAX_PURCHASE_PRICE, MIN_PURCHASE_PRICE))
}

is NumeralInputType.ProductSalePrice -> _uiState.update { currentState ->
Expand All @@ -111,11 +111,12 @@ class RegistrationViewModel @Inject constructor(
private fun formatPriceValue(
input: String,
maxValue: Int,
minValue: Int = 0,
): String {
if (input.isEmpty()) return ""

val rawValue = input.replace(",", "").toIntOrNull() ?: 0
val limitedValue = rawValue.coerceAtMost(maxValue)
val limitedValue = rawValue.coerceIn(minValue, maxValue)

return DecimalFormat("#,###").format(limitedValue)
}
Expand Down Expand Up @@ -183,11 +184,12 @@ class RegistrationViewModel @Inject constructor(
&& _uiState.value.productPurchasePrice.isNotEmpty()

val isPostFeeValid = when {
_uiState.value.isNormalPostChecked && _uiState.value.normalPostFee.isNotEmpty()
&& (!_uiState.value.isHalfPostChecked || _uiState.value.halfPostFee.isNotEmpty()) -> true
_uiState.value.isNormalPostChecked && (_uiState.value.normalPostFee.isNotEmpty() &&
_uiState.value.normalPostFee.priceToNumericTransformation() >= MIN_NORMAL_POST_FEE)
&& (!_uiState.value.isHalfPostChecked || (_uiState.value.halfPostFee.isNotEmpty() && _uiState.value.halfPostFee != ZERO)) -> true

!_uiState.value.isNormalPostChecked && _uiState.value.isHalfPostChecked
&& _uiState.value.halfPostFee.isNotEmpty() -> true
&& (_uiState.value.halfPostFee.isNotEmpty() && _uiState.value.halfPostFee != ZERO) -> true

else -> false
}
Expand Down Expand Up @@ -297,9 +299,12 @@ class RegistrationViewModel @Inject constructor(
private const val MAX_TITLE_LENGTH = 48
private const val MAX_DESCRIPTION_LENGTH = 240
private const val MAX_PURCHASE_PRICE = 999
private const val MIN_PURCHASE_PRICE = 1
private const val MAX_SALE_PRICE = 1_000_000
private const val MAX_NORMAL_POST_FEE = 30_000
private const val MIN_NORMAL_POST_FEE = 100
private const val MAX_HALF_POST_FEE = 5_000
private const val ZERO = "0"
private const val DEBOUNCE_DELAY = 500L
private const val KEY_DELIMITER = "image_"
private const val VALUE_DELIMITER = "?"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fun PostOptionCard(
.fillMaxWidth()
.background(NapzakMarketTheme.colors.white, RoundedCornerShape(12.dp))
.border(1.dp, NapzakMarketTheme.colors.gray200, RoundedCornerShape(12.dp))
.padding(vertical = 10.dp, horizontal = 15.dp),
.padding(vertical = 12.dp, horizontal = 15.dp),
) {
Row(
verticalAlignment = Alignment.CenterVertically,
Expand Down

0 comments on commit 25bc3e8

Please sign in to comment.