Skip to content

Commit

Permalink
feat: TodayScreen - TodayFragment 연결
Browse files Browse the repository at this point in the history
  • Loading branch information
oreocube committed Jan 15, 2025
1 parent f342073 commit f2e8592
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ class TodayFragment : Fragment() {
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
_binding = FragmentTodayBinding.inflate(inflater)
_binding = FragmentTodayBinding.inflate(inflater).apply {
titleSection.setContent {
TodayScreen(viewModel)
}
}
return binding.root
}

Expand Down Expand Up @@ -71,4 +75,4 @@ class TodayFragment : Fragment() {
super.onDestroyView()
_binding = null
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,30 @@ import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
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.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.presentation.ui.theme.Red02
import com.hrhn.presentation.ui.theme.SecondaryLabel
import com.hrhn.presentation.ui.theme.Typography
import com.hrhn.presentation.util.formatDateWithYearString

@Composable
fun TodayScreen(viewModel: TodayViewModel) {
val today by viewModel.today.collectAsStateWithLifecycle()
val todayString by remember(today) {
derivedStateOf { today.formatDateWithYearString() }
}

TodayHeader(today = todayString)
}

@Composable
fun TodayHeader(today: String) {
Expand Down
16 changes: 16 additions & 0 deletions app/src/main/java/com/hrhn/presentation/util/LocalDateTimeExt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.hrhn.presentation.util

import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.time.format.FormatStyle
import java.util.Locale

fun LocalDateTime.formatDateString(): String {
return format(DateTimeFormatter.ofPattern("MM/dd"))
}

fun LocalDateTime.formatDateWithYearString(): String {
return format(
DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM).withLocale(Locale.getDefault())
)
}
23 changes: 4 additions & 19 deletions app/src/main/res/layout/fragment_today.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,14 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/tv_title"
<androidx.compose.ui.platform.ComposeView
android:id="@+id/titleSection"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/space_default"
android:text="@string/title_today"
android:textAppearance="@style/HeaderText.Accent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/tv_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/space_text"
android:dateWithYear="@{vm.today}"
android:textAppearance="@style/CaptionText"
android:textColor="@color/secondary_label"
app:layout_constraintEnd_toEndOf="@id/tv_title"
app:layout_constraintStart_toStartOf="@id/tv_title"
app:layout_constraintTop_toBottomOf="@id/tv_title" />

<View
android:id="@+id/view_background"
android:layout_width="0dp"
Expand All @@ -60,7 +45,7 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_date" />
app:layout_constraintTop_toBottomOf="@id/titleSection" />

<androidx.constraintlayout.widget.Group
android:layout_width="wrap_content"
Expand Down Expand Up @@ -113,4 +98,4 @@
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</FrameLayout>
</layout>
</layout>

0 comments on commit f2e8592

Please sign in to comment.