Skip to content

Commit

Permalink
[REFACTOR/#305] Calendar 화면 리팩토링
Browse files Browse the repository at this point in the history
- 요일 enum 추가
- 컴포넌트 주석 추가
- 미사용 라이브러리 제거
  • Loading branch information
boiledEgg-s committed Dec 12, 2024
1 parent 64a1152 commit ee68943
Show file tree
Hide file tree
Showing 10 changed files with 159 additions and 153 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.terning.feature.calendar.calendar

import androidx.lifecycle.ViewModel
import com.terning.feature.calendar.calendar.model.DayModel
import com.terning.feature.calendar.calendar.model.CalendarUiState
import com.terning.feature.calendar.calendar.model.DayModel
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import com.terning.feature.calendar.R

/**
* 두 화면 간 전환을 담당하는 컴포넌트
*
* @param targetState 전환할 상태
* @param transitionOne 첫번째 화면에서 두번쨰 화면으로 이동할 때 발생할 전환 모션
* @param transitionTwo 두번째 화면에서 첫번째 화면으로 이동할 때 발생할 전환 모션
* @param contentOne 첫번째 화면
* @param contentTwo 두번째 화면
*/

@Composable
fun ScreenTransition(
targetState: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.terning.core.designsystem.theme.Black
import com.terning.core.designsystem.theme.SundayRed
import com.terning.core.designsystem.theme.TerningPointTheme
import com.terning.core.designsystem.theme.TerningTheme
import com.terning.feature.calendar.R
import com.terning.feature.calendar.calendar.type.WeekDay

@Composable
fun WeekDaysHeader(
Expand All @@ -31,21 +30,12 @@ fun WeekDaysHeader(
vertical = 18.dp
),
) {
val dayOfWeek = listOf(
R.string.calendar_text_sunday,
R.string.calendar_text_monday,
R.string.calendar_text_tuesday,
R.string.calendar_text_wednesday,
R.string.calendar_text_thursday,
R.string.calendar_text_friday,
R.string.calendar_text_saturday,
)
dayOfWeek.forEach { day ->
WeekDay.entries.forEach { day ->
Text(
modifier = Modifier.weight(1f),
text = stringResource(id = day),
text = day.nameInKorean,
style = TerningTheme.typography.body7,
color = if (day == R.string.calendar_text_sunday) SundayRed else Black,
color = if (WeekDay.isSunday(day)) SundayRed else Black,
textAlign = TextAlign.Center
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.terning.feature.calendar.calendar.component.dialog

import androidx.compose.runtime.Composable
import com.terning.feature.dialog.cancel.ScrapCancelDialog

/**
* 달력 스크랩 취소 다이얼로그
*
* @param scrapVisibility 스크랩 취소 다이얼로그 가시 여부
* @param internshipAnnouncementId 스크랩 취소를 진행할 공고 ID
* @param onDismissCancelDialog 스크랩 취소 다이얼로그 끄기
*/

@Composable
internal fun CalendarScrapCancelDialog(
scrapVisibility: Boolean,
internshipAnnouncementId: Long?,
onDismissCancelDialog: (Boolean) -> Unit,
) {
if (scrapVisibility) {
internshipAnnouncementId?.run {
ScrapCancelDialog(
internshipAnnouncementId = this,
onDismissRequest = onDismissCancelDialog
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.terning.feature.calendar.calendar.component.dialog

import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import com.terning.core.designsystem.extension.getFullDateStringInKorean
import com.terning.domain.calendar.entity.CalendarScrapDetail
import com.terning.feature.dialog.detail.ScrapDialog
import java.time.LocalDate

/**
* 달력 스크랩 디테일 다이얼로그
*
* @param date 선택된 날짜
* @param dialogVisibility 스크랩 디테일 다이얼로그 가시 여부
* @param internshipModel 스크랩 디테일
* @param navigateToAnnouncement 공고 상세로 이동하는 이동
* @param onDismissInternDialog 스크랩 디테일 다이얼로그 끄기
* @param onClickChangeColor 스크랩 색상 변경 시 발생하는 이벤트
*/

@Composable
internal fun CalendarScrapPatchDialog(
date: LocalDate,
dialogVisibility: Boolean,
internshipModel: CalendarScrapDetail?,
navigateToAnnouncement: (Long) -> Unit,
onDismissInternDialog: (Boolean) -> Unit,
onClickChangeColor: () -> Unit,
) {
if (dialogVisibility && internshipModel != null) {
val scrapColor = Color(
android.graphics.Color.parseColor(
internshipModel.color
)
)
ScrapDialog(
title = internshipModel.title,
scrapColor = scrapColor,
deadline = date.getFullDateStringInKorean(),
startYearMonth = internshipModel.startYearMonth,
workingPeriod = internshipModel.workingPeriod,
internshipAnnouncementId = internshipModel.internshipAnnouncementId,
companyImage = internshipModel.companyImage,
isScrapped = true,
onDismissRequest = onDismissInternDialog,
onClickChangeColor = onClickChangeColor,
onClickNavigateButton = navigateToAnnouncement
)
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.terning.feature.calendar.calendar.model

import androidx.compose.foundation.pager.PagerState
import androidx.compose.runtime.compositionLocalOf

data class CalendarUiState(
val selectedDate: DayModel = DayModel(),
val calendarModel: TerningCalendarModel = TerningCalendarModel(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.terning.feature.calendar.calendar.model

import androidx.compose.runtime.Immutable
import androidx.compose.runtime.staticCompositionLocalOf
import java.time.LocalDate
import java.time.YearMonth

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.terning.feature.calendar.calendar.type

enum class WeekDay(
val nameInKorean: String,
) {
SUNDAY(nameInKorean = ""),
MONDAY(nameInKorean = ""),
TUESDAY(nameInKorean = ""),
WEDNESDAY(nameInKorean = ""),
THURSDAY(nameInKorean = ""),
FRIDAY(nameInKorean = ""),
SATURDAY(nameInKorean = "");

companion object {
fun isSunday(weekDay: WeekDay): Boolean {
return weekDay == SUNDAY
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
Expand All @@ -38,11 +37,11 @@ import com.terning.core.designsystem.theme.Grey400
import com.terning.core.designsystem.theme.TerningTheme
import com.terning.domain.calendar.entity.CalendarScrapDetail
import com.terning.feature.calendar.R
import com.terning.feature.calendar.calendar.component.dialog.CalendarScrapCancelDialog
import com.terning.feature.calendar.calendar.component.dialog.CalendarScrapPatchDialog
import com.terning.feature.calendar.calendar.component.group.CalendarScrapListGroup
import com.terning.feature.calendar.calendar.model.TerningCalendarModel
import com.terning.feature.calendar.list.model.CalendarListUiState
import com.terning.feature.dialog.cancel.ScrapCancelDialog
import com.terning.feature.dialog.detail.ScrapDialog
import okhttp3.internal.toImmutableList
import java.time.LocalDate

Expand All @@ -56,9 +55,10 @@ fun CalendarListRoute(
viewModel: CalendarListViewModel = hiltViewModel(),
) {
val lifecycleOwner = LocalLifecycleOwner.current
val uiState by viewModel.uiState.collectAsStateWithLifecycle(lifecycleOwner)
val context = LocalContext.current

val uiState by viewModel.uiState.collectAsStateWithLifecycle()

LaunchedEffect(viewModel.sideEffect, lifecycleOwner) {
viewModel.sideEffect.flowWithLifecycle(lifecycle = lifecycleOwner.lifecycle)
.collect { sideEffect ->
Expand Down Expand Up @@ -100,8 +100,8 @@ fun CalendarListRoute(
}
)

CalendarListScrapPatchDialog(
currentDate = uiState.currentDate,
CalendarScrapPatchDialog(
date = uiState.currentDate,
dialogVisibility = uiState.scrapDetailDialogVisibility,
internshipModel = uiState.internshipModel,
navigateToAnnouncement = { announcementId ->
Expand All @@ -114,7 +114,7 @@ fun CalendarListRoute(
},
)

CalendarListScrapCancelDialog(
CalendarScrapCancelDialog(
scrapVisibility = uiState.scrapCancelDialogVisibility,
internshipAnnouncementId = uiState.internshipAnnouncementId,
onDismissCancelDialog = { isCancelled ->
Expand All @@ -140,7 +140,6 @@ private fun CalendarListScreen(
state = pagerState,
modifier = modifier
) { page ->
val getDate = calendarModel.getLocalDateByPage(page)

LazyColumn(
modifier = Modifier
Expand All @@ -163,31 +162,15 @@ private fun CalendarListScreen(

is UiState.Failure -> {}
is UiState.Success -> {
val scrapMap = uiState.loadState.data
items(getDate.lengthOfMonth()) { day ->
val currentDate =
LocalDate.of(getDate.year, getDate.monthValue, day + 1)
val dateInKorean = currentDate.getFullDateStringInKorean()

if (scrapMap[dateInKorean].isListNotEmpty()) {
Text(
text = dateInKorean,
style = TerningTheme.typography.title5,
color = Black,
modifier = Modifier
.padding(start = 24.dp, top = 16.dp, bottom = 15.dp)
)

CalendarScrapListGroup(
scrapList = scrapMap[dateInKorean].orEmpty().toImmutableList(),
onScrapButtonClicked = onClickScrapButton,
onInternshipClicked = onClickInternship,
isFromList = true,
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 24.dp)
)
}
val date = calendarModel.getLocalDateByPage(page)

items(date.lengthOfMonth()) { day ->
CalendarListSuccess(
date = LocalDate.of(date.year, date.monthValue, day + 1),
scrapMap = uiState.loadState.data,
onClickScrapButton = onClickScrapButton,
onClickInternship = onClickInternship,
)
}
}
}
Expand Down Expand Up @@ -218,50 +201,32 @@ private fun CalendarListEmpty(
}

@Composable
private fun CalendarListScrapCancelDialog(
scrapVisibility: Boolean,
internshipAnnouncementId: Long?,
onDismissCancelDialog: (Boolean) -> Unit,
) {
if (scrapVisibility) {
internshipAnnouncementId?.run {
ScrapCancelDialog(
internshipAnnouncementId = this,
onDismissRequest = onDismissCancelDialog
)
}
}
}

@Composable
private fun CalendarListScrapPatchDialog(
currentDate: LocalDate,
dialogVisibility: Boolean,
internshipModel: CalendarScrapDetail?,
navigateToAnnouncement: (Long) -> Unit,
onDismissInternDialog: (Boolean) -> Unit,
onClickChangeColor: () -> Unit,
private fun CalendarListSuccess(
date: LocalDate,
scrapMap: Map<String, List<CalendarScrapDetail>>,
onClickScrapButton: (Long) -> Unit,
onClickInternship: (CalendarScrapDetail) -> Unit,
modifier: Modifier = Modifier,
) {
if (dialogVisibility) {
internshipModel?.let { internship ->
val scrapColor = Color(
android.graphics.Color.parseColor(
internship.color
)
)
ScrapDialog(
title = internship.title,
scrapColor = scrapColor,
deadline = currentDate.getFullDateStringInKorean(),
startYearMonth = internship.startYearMonth,
workingPeriod = internship.workingPeriod,
internshipAnnouncementId = internship.internshipAnnouncementId,
companyImage = internship.companyImage,
isScrapped = true,
onDismissRequest = onDismissInternDialog,
onClickChangeColor = onClickChangeColor,
onClickNavigateButton = navigateToAnnouncement
)
}
val dateInKorean = date.getFullDateStringInKorean()

if (scrapMap[dateInKorean].isListNotEmpty()) {
Text(
text = dateInKorean,
style = TerningTheme.typography.title5,
color = Black,
modifier = modifier
.padding(start = 24.dp, top = 16.dp, bottom = 15.dp)
)

CalendarScrapListGroup(
scrapList = scrapMap[dateInKorean].orEmpty().toImmutableList(),
onScrapButtonClicked = onClickScrapButton,
onInternshipClicked = onClickInternship,
isFromList = true,
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 24.dp)
)
}
}
Loading

0 comments on commit ee68943

Please sign in to comment.