Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/ledger edit date #119

Merged
merged 2 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,20 @@ data class LedgerEditState(
val startYear: Int = 0,
val startMonth: Int = 0,
val startDay: Int = 0,
val endYear: Int = 0,
val endMonth: Int = 0,
val endDay: Int = 0,
val endYear: Int? = null,
val endMonth: Int? = null,
val endDay: Int? = null,
val categoryConfigList: PersistentList<Category> = persistentListOf(Category()),
val showCustomCategoryButton: Boolean = false,
val isCustomCategoryChipSaved: Boolean = false,
val showStartDateBottomSheet: Boolean = false,
val showEndDateBottomSheet: Boolean = false,
val showOnlyStartDate: Boolean = false,
) : UiState {
val isSelectedCustomCategory = selectedCategoryId == categoryConfigList.last().id
val saveButtonEnabled = when {
name.isEmpty() -> false
endYear == null -> false
isSelectedCustomCategory && (customCategory.isEmpty() || isCustomCategoryChipSaved.not()) -> false
else -> true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import androidx.compose.foundation.layout.imePadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
Expand All @@ -21,6 +22,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
Expand All @@ -31,18 +33,25 @@ import com.susu.core.designsystem.component.appbar.icon.BackIcon
import com.susu.core.designsystem.component.bottomsheet.datepicker.SusuLimitDatePickerBottomSheet
import com.susu.core.designsystem.component.button.AddConditionButton
import com.susu.core.designsystem.component.button.FilledButtonColor
import com.susu.core.designsystem.component.button.LinedButtonColor
import com.susu.core.designsystem.component.button.MediumButtonStyle
import com.susu.core.designsystem.component.button.SmallButtonStyle
import com.susu.core.designsystem.component.button.SusuFilledButton
import com.susu.core.designsystem.component.button.SusuLinedButton
import com.susu.core.designsystem.component.button.XSmallButtonStyle
import com.susu.core.designsystem.component.textfield.SusuBasicTextField
import com.susu.core.designsystem.component.textfieldbutton.SusuTextFieldWrapContentButton
import com.susu.core.designsystem.component.textfieldbutton.TextFieldButtonColor
import com.susu.core.designsystem.component.textfieldbutton.style.SmallTextFieldButtonStyle
import com.susu.core.designsystem.theme.Gray100
import com.susu.core.designsystem.theme.Gray30
import com.susu.core.designsystem.theme.Gray80
import com.susu.core.designsystem.theme.Orange60
import com.susu.core.designsystem.theme.SusuTheme
import com.susu.core.ui.extension.collectWithLifecycle
import com.susu.core.ui.extension.susuClickable
import com.susu.core.ui.util.AnnotatedText
import com.susu.core.ui.util.currentDate
import com.susu.feature.received.R
import com.susu.feature.received.ledgeredit.component.LedgerEditContainer
import kotlinx.coroutines.android.awaitFrame
Expand Down Expand Up @@ -90,6 +99,8 @@ fun LedgerEditRoute(
onClickEndDateText = viewModel::showEndDateBottomSheet,
onDismissEndDateBottomSheet = viewModel::hideEndDateBottomSheet,
onClickSaveButton = viewModel::editLedger,
onClickAddEndDateButton = viewModel::showEndDateText,
onClickSetStartDateButton = viewModel::showOnlyStartDateText,
)
}

Expand All @@ -113,6 +124,8 @@ fun LedgerEditScreen(
onClickEndDateText: () -> Unit = {},
onDismissEndDateBottomSheet: () -> Unit = {},
onClickSaveButton: () -> Unit = {},
onClickAddEndDateButton: () -> Unit = {},
onClickSetStartDateButton: () -> Unit = {},
) {
Box(
modifier = Modifier
Expand Down Expand Up @@ -195,35 +208,64 @@ fun LedgerEditScreen(
AnnotatedText(
modifier = Modifier.susuClickable(rippleEnabled = false, onClick = onClickStartDateText),
originalText = stringResource(
R.string.ledger_edit_screen_from_date,
if (uiState.showOnlyStartDate) R.string.ledger_edit_screen_date else R.string.ledger_edit_screen_from_date,
uiState.startYear,
uiState.startMonth,
uiState.startDay,
),
targetTextList = listOf(
stringResource(R.string.ledger_edit_screen_year),
stringResource(R.string.ledger_edit_screen_month),
stringResource(R.string.ledger_edit_screen_from_day),
),
originalTextStyle = SusuTheme.typography.title_m,
spanStyle = SusuTheme.typography.title_m.copy(Gray80).toSpanStyle(),
)
AnnotatedText(
modifier = Modifier.susuClickable(rippleEnabled = false, onClick = onClickEndDateText),
originalText = stringResource(
R.string.ledger_edit_screen_until_date,
uiState.endYear,
uiState.endMonth,
uiState.endDay,
),
targetTextList = listOf(
stringResource(R.string.ledger_edit_screen_year),
stringResource(R.string.ledger_edit_screen_month),
stringResource(R.string.ledger_edit_screen_until_day),
stringResource(
if (uiState.showOnlyStartDate) R.string.ledger_edit_screen_day else R.string.ledger_edit_screen_from_day,
),
),
originalTextStyle = SusuTheme.typography.title_m,
spanStyle = SusuTheme.typography.title_m.copy(Gray80).toSpanStyle(),
)

if (uiState.showOnlyStartDate.not()) {
AnnotatedText(
modifier = Modifier.susuClickable(rippleEnabled = false, onClick = onClickEndDateText),
originalText = stringResource(
R.string.ledger_edit_screen_until_date,
uiState.endYear ?: currentDate.year,
uiState.endMonth ?: currentDate.month.value,
uiState.endDay ?: currentDate.dayOfMonth,
),
targetTextList = listOf(
stringResource(R.string.ledger_edit_screen_year),
stringResource(R.string.ledger_edit_screen_month),
stringResource(R.string.ledger_edit_screen_until_day),
),
originalTextStyle = SusuTheme.typography.title_m.copy(if (uiState.endYear == null) Gray30 else Gray100),
spanStyle = SusuTheme.typography.title_m.copy(Gray80).toSpanStyle(),
)
}

Spacer(modifier = Modifier.size(SusuTheme.spacing.spacing_xxs))

if (uiState.showOnlyStartDate) {
SusuLinedButton(
color = LinedButtonColor.Orange,
style = XSmallButtonStyle.height28,
text = stringResource(R.string.ledger_edit_screen_add_end_date),
leftIcon = {
Icon(painter = painterResource(id = R.drawable.ic_date_change), contentDescription = null, tint = Orange60)
},
onClick = onClickAddEndDateButton,
)
} else {
SusuLinedButton(
color = LinedButtonColor.Orange,
style = XSmallButtonStyle.height28,
text = stringResource(R.string.ledger_edit_screen_add_start_date),
leftIcon = {
Icon(painter = painterResource(id = R.drawable.ic_date_change), contentDescription = null, tint = Orange60)
},
onClick = onClickSetStartDateButton,
)
}
}
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class LedgerEditViewModel @Inject constructor(
id = ledgerId,
title = name,
startAt = LocalDateTime.of(startYear, startMonth, startDay, 0, 0).toKotlinLocalDateTime(),
endAt = LocalDateTime.of(endYear, endMonth, endDay, 0, 0).toKotlinLocalDateTime(),
endAt = LocalDateTime.of(endYear ?: startYear, endMonth ?: startMonth, endDay ?: startDay, 0, 0).toKotlinLocalDateTime(),
category = Category(
id = selectedCategoryId,
customCategory = customCategory.ifEmpty { null },
Expand Down Expand Up @@ -75,6 +75,7 @@ class LedgerEditViewModel @Inject constructor(
endYear = endDate.year,
endMonth = endDate.monthValue,
endDay = endDate.dayOfMonth,
showOnlyStartDate = startDate == endDate,
customCategory = customCategory ?: "",
isCustomCategoryChipSaved = customCategory.isNullOrEmpty().not(),
showCustomCategoryButton = ledger.category.customCategory != null,
Expand Down Expand Up @@ -147,4 +148,21 @@ class LedgerEditViewModel @Inject constructor(
fun hideEndDateBottomSheet() = intent { copy(showEndDateBottomSheet = false) }

fun popBackStack() = postSideEffect(LedgerEditSideEffect.PopBackStack)
fun showEndDateText() = intent {
copy(
endYear = null,
endMonth = null,
endDay = null,
showOnlyStartDate = false,
)
}

fun showOnlyStartDateText() = intent {
copy(
endYear = startYear,
endMonth = startMonth,
endDay = startDay,
showOnlyStartDate = true,
)
}
}
10 changes: 10 additions & 0 deletions feature/received/src/main/res/drawable/ic_date_change.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="12dp"
android:height="12dp"
android:viewportWidth="12"
android:viewportHeight="12">
<path
android:pathData="M7.896,1.396C8.092,1.201 8.408,1.201 8.604,1.396L10.354,3.146C10.549,3.342 10.549,3.658 10.354,3.854L8.604,5.604C8.408,5.799 8.092,5.799 7.896,5.604C7.701,5.408 7.701,5.092 7.896,4.896L8.793,4H3.5C3.224,4 3,3.776 3,3.5C3,3.224 3.224,3 3.5,3H8.793L7.896,2.104C7.701,1.908 7.701,1.592 7.896,1.396ZM4.104,6.396C4.299,6.592 4.299,6.908 4.104,7.104L3.207,8H8C8.276,8 8.5,8.224 8.5,8.5C8.5,8.776 8.276,9 8,9H3.207L4.104,9.896C4.299,10.092 4.299,10.408 4.104,10.604C3.908,10.799 3.592,10.799 3.396,10.604L1.646,8.854C1.451,8.658 1.451,8.342 1.646,8.146L3.396,6.396C3.592,6.201 3.908,6.201 4.104,6.396Z"
android:fillColor="#FFA500"
android:fillType="evenOdd"/>
</vector>
4 changes: 4 additions & 0 deletions feature/received/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
<string name="ledger_detail_screen_empty_envelope">์•„์ง ๋ณด๋‚ธ ๋ด‰ํˆฌ๊ฐ€ ์—†์–ด์š”</string>
<string name="ledger_detail_screen_add_envelope">๋ฐ›์€ ๋ด‰ํˆฌ ์ถ”๊ฐ€ํ•˜๊ธฐ</string>
<string name="ledger_edit_screen_from_date">%d๋…„ %d์›” %d์ผ ๋ถ€ํ„ฐ</string>
<string name="ledger_edit_screen_date">%d๋…„ %d์›” %d์ผ</string>
<string name="ledger_edit_screen_until_date">%d๋…„ %d์›” %d์ผ ๊นŒ์ง€</string>
<string name="ledger_edit_screen_year">๋…„</string>
<string name="ledger_edit_screen_month">์›”</string>
<string name="ledger_edit_screen_from_day">์ผ ๋ถ€ํ„ฐ</string>
<string name="ledger_edit_screen_day">์ผ</string>
<string name="ledger_edit_screen_until_day">์ผ ๊นŒ์ง€</string>
<string name="ledger_filter_screen_from">๋ถ€ํ„ฐ</string>
<string name="ledger_filter_screen_until">๊นŒ์ง€</string>
Expand Down Expand Up @@ -64,4 +66,6 @@
<string name="dialog_delete_envelope_title">๋ด‰ํˆฌ๋ฅผ ์‚ญ์ œํ• ๊นŒ์š”?</string>
<string name="dialog_delete_envelope_text">์‚ญ์ œํ•œ ๋ด‰ํˆฌ๋Š” ๋‹ค์‹œ ๋ณต๊ตฌํ•  ์ˆ˜ ์—†์–ด์š”</string>
<string name="toast_delete_envelope_success">๋ด‰ํˆฌ๊ฐ€ ์‚ญ์ œ๋์–ด์š”</string>
<string name="ledger_edit_screen_add_end_date">์ข…๋ฃŒ์ผ ์ถ”๊ฐ€</string>
<string name="ledger_edit_screen_add_start_date">์‹œ์ž‘์ผ๋งŒ ์ง€์ •</string>
</resources>
Loading