-
Notifications
You must be signed in to change notification settings - Fork 1
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
[UI/#305] 캘린터 터치 영역 수정 #311
base: develop
Are you sure you want to change the base?
Changes from all commits
0a01f9d
d2ba1a2
4f25500
3f8d781
15744dd
fb39552
64a1152
ee68943
3dbc4a6
2743ab1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,22 @@ | ||
package com.terning.feature.calendar.calendar | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
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 | ||
import kotlinx.coroutines.flow.update | ||
import kotlinx.coroutines.launch | ||
import java.time.LocalDate | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class CalendarViewModel @Inject constructor() : ViewModel() { | ||
private var _uiState: MutableStateFlow<CalendarUiState> = MutableStateFlow(CalendarUiState()) | ||
val uiState get() = _uiState.asStateFlow() | ||
|
||
fun onSelectNewDate(selectedDate: LocalDate) = viewModelScope.launch { | ||
if (_uiState.value.selectedDate == selectedDate) { | ||
_uiState.update { currentState -> | ||
currentState.copy( | ||
isWeekEnabled = !_uiState.value.isWeekEnabled | ||
) | ||
} | ||
fun onSelectNewDate(selectedDate: DayModel) { | ||
if (_uiState.value.selectedDate.date == selectedDate.date) { | ||
updateWeekVisibility(!_uiState.value.isWeekEnabled) | ||
} else { | ||
_uiState.update { currentState -> | ||
currentState.copy( | ||
|
@@ -33,27 +27,23 @@ class CalendarViewModel @Inject constructor() : ViewModel() { | |
} | ||
} | ||
|
||
fun updateSelectedDate(date: LocalDate) = viewModelScope.launch { | ||
_uiState.update { currentState -> | ||
fun updateSelectedDate(value: DayModel) = _uiState.update { currentState -> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. update 함수들의 파라미터 이름을 value로 수정하신 이유가 궁금해요!! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 함수명에서 무엇을 구현하는지 명시해뒀는데 굳이 한번 더 명시할 필요가 있을까 싶었고, 모든 flow 업데이트 함수를 일관되게 관리하고자 value라고 수정했습니다! |
||
currentState.copy( | ||
selectedDate = date | ||
selectedDate = value | ||
) | ||
} | ||
} | ||
|
||
fun updateListVisibility(visibility: Boolean) = viewModelScope.launch { | ||
_uiState.update { currentState -> | ||
|
||
fun updateListVisibility(value: Boolean) = _uiState.update { currentState -> | ||
currentState.copy( | ||
isListEnabled = visibility | ||
isListEnabled = value | ||
) | ||
} | ||
Comment on lines
+36
to
41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 상태를 업데이트할 때 이렇게 표현식을 사용해도 되는군요..! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. update라는 블록함수를 사용하면 Flow를 원자적으로 업데이트한다고 합니다! |
||
} | ||
|
||
fun updateWeekVisibility(visibility: Boolean) = viewModelScope.launch { | ||
_uiState.update { currentState -> | ||
|
||
fun updateWeekVisibility(value: Boolean) = _uiState.update { currentState -> | ||
currentState.copy( | ||
isWeekEnabled = visibility | ||
isWeekEnabled = value | ||
) | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
함수화를 해놓으니 훨씬 가독성이 좋아졌네요!