Skip to content

Commit

Permalink
[MERGE] #129 -> develop
Browse files Browse the repository at this point in the history
[FEAT/#129] ์บ˜๋ฆฐ๋”๋ทฐ / ์Šคํฌ๋žฉ ์„œ๋ฒ„ ํ†ต์‹  ๊ตฌํ˜„
  • Loading branch information
boiledEgg-s authored Jul 18, 2024
2 parents 3b3ac7f + 230ac2c commit 338fdb0
Show file tree
Hide file tree
Showing 11 changed files with 232 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fun CalendarTopAppBar(
Icon(
painter = painterResource(id = R.drawable.ic_calendar_previous),
contentDescription = stringResource(id = R.string.calendar_button_description_previous),
tint = Grey300,
tint = TerningMain,
modifier = Modifier.noRippleClickable { onMonthNavigationButtonClicked(-1) }
)
}
Expand All @@ -68,7 +68,7 @@ fun CalendarTopAppBar(
Icon(
painter = painterResource(id = R.drawable.ic_calendar_next),
contentDescription = stringResource(id = R.string.calendar_button_description_next),
tint = Grey300,
tint = TerningMain,
modifier = Modifier.noRippleClickable { onMonthNavigationButtonClicked(1) }
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ class ScrapRepositoryImpl @Inject constructor(
: Result<Unit> = runCatching {
scrapDataSource.deleteScrap(scrapRequestModel)
}

override suspend fun patchScrap(scrapRequestModel: ScrapRequestModel)
: Result<Unit> = runCatching {
scrapDataSource.patchScrap(scrapRequestModel)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ import com.terning.domain.entity.request.ScrapRequestModel
interface ScrapRepository {
suspend fun postScrap(scrapRequestModel: ScrapRequestModel): Result<Unit>
suspend fun deleteScrap(scrapRequestModel: ScrapRequestModel): Result<Unit>
suspend fun patchScrap(scrapRequestModel: ScrapRequestModel): Result<Unit>
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private fun CalendarScreen(
CalendarTopAppBar(
date = currentDate,
isListExpanded = calendarUiState.isListEnabled,
isWeekExpanded = calendarUiState.isListEnabled,
isWeekExpanded = calendarUiState.isWeekEnabled,
onListButtonClicked = {
viewModel.changeListVisibility()
if (calendarUiState.isWeekEnabled) {
Expand Down Expand Up @@ -163,8 +163,9 @@ private fun CalendarScreen(
},
contentTwo = {
CalendarWeekScreen(
uiState = calendarUiState,
calendarUiState = calendarUiState,
viewModel = viewModel,
navController = navController,
modifier = Modifier
.fillMaxSize(),
)
Expand All @@ -177,7 +178,7 @@ private fun CalendarScreen(
listState = listState,
pages = state.getPageCount(),
viewModel = viewModel,
uiState = calendarUiState,
navController = navController,
modifier = Modifier
.fillMaxSize()
.padding(top = paddingValues.calculateTopPadding())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
package com.terning.feature.calendar.calendar

import android.util.Log
import androidx.compose.ui.graphics.Color
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.terning.core.designsystem.theme.CalBlue1
import com.terning.core.designsystem.theme.CalBlue2
import com.terning.core.designsystem.theme.CalGreen1
import com.terning.core.designsystem.theme.CalGreen2
import com.terning.core.designsystem.theme.CalOrange1
import com.terning.core.designsystem.theme.CalOrange2
import com.terning.core.designsystem.theme.CalPink
import com.terning.core.designsystem.theme.CalPurple
import com.terning.core.designsystem.theme.CalRed
import com.terning.core.designsystem.theme.CalYellow
import com.terning.core.state.UiState
import com.terning.domain.entity.request.ScrapRequestModel
import com.terning.domain.entity.response.CalendarScrapDetailModel
import com.terning.domain.repository.CalendarRepository
import com.terning.domain.repository.ScrapRepository
import com.terning.feature.R
import com.terning.feature.calendar.month.CalendarMonthState
import com.terning.feature.calendar.scrap.CalendarListState
import com.terning.feature.calendar.week.CalendarWeekState
import com.terning.feature.intern.model.InternScrapState
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableSharedFlow
Expand All @@ -18,13 +33,13 @@ import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import timber.log.Timber
import java.time.LocalDate
import javax.inject.Inject

@HiltViewModel
class CalendarViewModel @Inject constructor(
private val calendarRepository: CalendarRepository
private val calendarRepository: CalendarRepository,
private val scrapRepository: ScrapRepository
) : ViewModel() {

private var _uiState: MutableStateFlow<CalendarUiState> = MutableStateFlow(
Expand Down Expand Up @@ -91,10 +106,17 @@ class CalendarViewModel @Inject constructor(
}
}

fun updateInternDialogVisible(scrapDetailModel: CalendarScrapDetailModel?) {
fun updateInternDialogVisible(visibility: Boolean = false) {
_uiState.update { currentState ->
currentState.copy(
isInternshipClicked = visibility
)
}
}

fun updateInternshipModel(scrapDetailModel: CalendarScrapDetailModel?) {
_uiState.update { currentState ->
currentState.copy(
isInternshipClicked = !currentState.isInternshipClicked,
internshipModel = scrapDetailModel
)
}
Expand Down Expand Up @@ -153,7 +175,6 @@ class CalendarViewModel @Inject constructor(
_calendarWeekState.update { currentState ->
currentState.copy(
loadState = if (it.isNotEmpty()) UiState.Success(it) else UiState.Empty
//loadState = UiState.Success(it)
)
}
},
Expand All @@ -168,4 +189,66 @@ class CalendarViewModel @Inject constructor(
}
)
}

fun deleteScrap(isFromWeekScreen: Boolean = false) = viewModelScope.launch {
_calendarWeekState.value.loadState
.takeIf { it is UiState.Success }
?.let { ScrapRequestModel(_uiState.value.scrapId, null) }?.let { scrapRequestModel ->
scrapRepository.deleteScrap(
scrapRequestModel
).onSuccess {
runCatching {
if (isFromWeekScreen) {
getScrapWeekList()
} else {
getScrapMonthList(
_uiState.value.selectedDate.year,
_uiState.value.selectedDate.monthValue
)
}
}.onSuccess {
updateScrapCancelDialogVisible()
}
}.onFailure {
_calendarSideEffect.emit(
CalendarSideEffect.ShowToast(R.string.server_failure)
)
}
}
}

fun patchScrap(color: Color, isFromWeekScreen: Boolean = false) = viewModelScope.launch {
val scrapId = _uiState.value.internshipModel?.scrapId ?: 0
val colorIndex = getColorIndex(color)

scrapRepository.patchScrap(ScrapRequestModel(scrapId, colorIndex))
.onSuccess {
runCatching {
if (isFromWeekScreen) {
getScrapWeekList()
} else {
getScrapMonthList(
_uiState.value.selectedDate.year,
_uiState.value.selectedDate.monthValue
)
}
}
}.onFailure {
_calendarSideEffect.emit(CalendarSideEffect.ShowToast(R.string.server_failure))
}
}

private fun getColorIndex(color: Color): Int = listOf(
CalRed,
CalOrange1,
CalOrange2,
CalYellow,
CalGreen1,
CalGreen2,
CalBlue1,
CalBlue2,
CalPurple,
CalPink
).indexOf(color)

}
Loading

0 comments on commit 338fdb0

Please sign in to comment.