-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from hyeeyoung/dev-fix-calendar-bug
μΊλ¦°λμμ μμΈλ·° μ΄λ ν 볡κ·νμ λ μνκ°μ΄ μ΄κΈ°νλλ λ²κ·Έ μμ
- Loading branch information
Showing
4 changed files
with
59 additions
and
25 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
app/src/main/java/com/hyeeyoung/wishboard/presentation/calendar/CalendarViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.hyeeyoung.wishboard.presentation.calendar | ||
|
||
import androidx.lifecycle.ViewModel | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import java.time.LocalDate | ||
|
||
class CalendarViewModel : ViewModel() { | ||
private val _selectedDate = MutableStateFlow(LocalDate.now()) | ||
val selectedDate get() = _selectedDate.asStateFlow() | ||
|
||
private val latestCalendarPage = MutableStateFlow(INITIAL_PAGE) | ||
|
||
fun changeCalendarPage(currentPate: Int) { | ||
val diff = currentPate - latestCalendarPage.value | ||
|
||
if (diff < 0) { | ||
_selectedDate.value = _selectedDate.value.minusMonths(1) | ||
} else if (diff > 0) { | ||
_selectedDate.value = _selectedDate.value.plusMonths(1) | ||
} | ||
|
||
latestCalendarPage.value = currentPate | ||
} | ||
|
||
fun updateSelectedDate(date: LocalDate) { | ||
_selectedDate.value = date | ||
} | ||
|
||
companion object { | ||
const val PAGE_COUNT = Int.MAX_VALUE | ||
const val INITIAL_PAGE = PAGE_COUNT / 2 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters