Skip to content

Commit

Permalink
feat: TodayCard 컴포저블 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
oreocube committed Jan 20, 2025
1 parent f2e8592 commit fed9ebf
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class TodayFragment : Fragment() {
savedInstanceState: Bundle?
): View {
_binding = FragmentTodayBinding.inflate(inflater).apply {
titleSection.setContent {
composeView.setContent {
TodayScreen(viewModel)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
package com.hrhn.presentation.ui.screen.main.today

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.hrhn.R
import com.hrhn.domain.model.Challenge
import com.hrhn.presentation.ui.theme.CellFill
import com.hrhn.presentation.ui.theme.CellLabel
import com.hrhn.presentation.ui.theme.Gray54
import com.hrhn.presentation.ui.theme.Red02
import com.hrhn.presentation.ui.theme.SecondaryLabel
import com.hrhn.presentation.ui.theme.Typography
import com.hrhn.presentation.ui.theme.White
import com.hrhn.presentation.util.formatDateWithYearString

@Composable
Expand All @@ -26,12 +38,26 @@ fun TodayScreen(viewModel: TodayViewModel) {
val todayString by remember(today) {
derivedStateOf { today.formatDateWithYearString() }
}
val todayChallenge by viewModel.todayChallengeFlow.collectAsStateWithLifecycle()

TodayHeader(today = todayString)
Column(
modifier = Modifier.fillMaxSize(),
horizontalAlignment = Alignment.CenterHorizontally
) {
TodayHeader(today = todayString)
TodayCard(
modifier = Modifier
.weight(1f)
.padding(start = 40.dp, end = 40.dp, top = 16.dp, bottom = 40.dp),
challenge = todayChallenge,
onCardClick = viewModel::editTodayChallenge,
onAddClick = viewModel::addTodayChallenge,
)
}
}

@Composable
fun TodayHeader(today: String) {
private fun TodayHeader(today: String) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
) {
Expand All @@ -49,8 +75,64 @@ fun TodayHeader(today: String) {
}
}

@Composable
private fun TodayCard(
modifier: Modifier = Modifier,
challenge: Challenge?,
onCardClick: () -> Unit,
onAddClick: () -> Unit,
) {
Column(
modifier = modifier
.fillMaxSize()
.clip(RoundedCornerShape(size = 16.dp))
.background(color = CellFill)
.clickable(
enabled = challenge != null,
onClick = onCardClick,
),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally,
) {
if (challenge == null) {
Text(
text = stringResource(id = R.string.message_no_challenge),
style = Typography.labelSmall,
color = Gray54,
)
Spacer(modifier = Modifier.height(16.dp))
Text(
modifier = Modifier
.clip(RoundedCornerShape(50.dp))
.background(Red02)
.clickable(onClick = onAddClick)
.padding(horizontal = 24.dp, vertical = 12.dp),
text = stringResource(id = R.string.button_add_challenge),
style = Typography.labelSmall,
color = White,
)
} else {
Text(
text = challenge.content,
style = Typography.titleLarge,
color = CellLabel,
)
}
}
}

@Preview(showBackground = true)
@Composable
fun TodayHeaderPreview() {
private fun TodayHeaderPreview() {
TodayHeader(today = "2025.01.15")
}

@Preview(showBackground = true)
@Composable
private fun TodayCardPreview() {
TodayCard(
challenge = Challenge(content = "빨래널기"),
onCardClick = {},
onAddClick = {},
)
}
4 changes: 2 additions & 2 deletions app/src/main/java/com/hrhn/presentation/ui/theme/Color.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ val HeaderLabel = Black
//val dim = Gray54
//val background = White
//val setting_icon_fill = GrayC5
//val cell_fill = GrayFB
//val cell_label = Gray4A
val CellFill = GrayFB
val CellLabel = Gray4A
66 changes: 1 addition & 65 deletions app/src/main/res/layout/fragment_today.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,76 +25,12 @@
android:layout_height="match_parent">

<androidx.compose.ui.platform.ComposeView
android:id="@+id/titleSection"
android:id="@+id/composeView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<View
android:id="@+id/view_background"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginHorizontal="@dimen/space_large"
android:layout_marginTop="@dimen/space_default"
android:layout_marginBottom="@dimen/space_large"
android:background="@drawable/bg_challenge_card"
android:clickable="@{!vm.isEmpty()}"
android:onClick="@{() -> vm.editTodayChallenge()}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/titleSection" />

<androidx.constraintlayout.widget.Group
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibleIf="@{vm.isEmpty()}"
app:constraint_referenced_ids="tv_no_challenge, btn_add_challenge" />

<TextView
android:id="@+id/tv_no_challenge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/message_no_challenge"
android:textAppearance="@style/CaptionText"
android:textColor="@color/dim"
app:layout_constraintBottom_toTopOf="@id/btn_add_challenge"
app:layout_constraintEnd_toEndOf="@id/view_background"
app:layout_constraintStart_toStartOf="@id/view_background"
app:layout_constraintTop_toTopOf="@id/view_background"
app:layout_constraintVertical_chainStyle="packed" />

<com.google.android.material.button.MaterialButton
android:id="@+id/btn_add_challenge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/space_text"
android:onClick="@{()->vm.addTodayChallenge()}"
android:text="@string/button_add_challenge"
android:textAppearance="@style/CaptionText"
android:textColor="@color/white_label"
app:cornerRadius="@dimen/radius_button"
app:layout_constraintBottom_toBottomOf="@id/view_background"
app:layout_constraintEnd_toEndOf="@id/tv_no_challenge"
app:layout_constraintStart_toStartOf="@id/tv_no_challenge"
app:layout_constraintTop_toBottomOf="@id/tv_no_challenge" />

<TextView
android:id="@+id/tv_today_challenge"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_margin="@dimen/space_large"
android:gravity="center"
android:text="@{vm.todayChallengeFlow.content}"
android:textAppearance="@style/HeaderText"
android:textColor="@color/cell_label"
android:visibleIf="@{!vm.isEmpty()}"
app:layout_constraintBottom_toBottomOf="@id/view_background"
app:layout_constraintEnd_toEndOf="@id/view_background"
app:layout_constraintStart_toStartOf="@id/view_background"
app:layout_constraintTop_toTopOf="@id/view_background" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</FrameLayout>
Expand Down

0 comments on commit fed9ebf

Please sign in to comment.