Skip to content

Commit 8b83609

Browse files
committed
[FEAT/#167] 보상 존재에 따른 버튼 분기처리
1 parent 00aac0a commit 8b83609

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

feature/fortune/src/main/java/com/yapp/fortune/FortuneViewModel.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import kotlinx.coroutines.launch
1818
import org.orbitmvi.orbit.syntax.simple.intent
1919
import org.orbitmvi.orbit.syntax.simple.postSideEffect
2020
import org.orbitmvi.orbit.syntax.simple.reduce
21+
import java.time.LocalDate
22+
import java.time.format.DateTimeFormatter
2123
import javax.inject.Inject
2224

2325
@HiltViewModel
@@ -33,18 +35,21 @@ class FortuneViewModel @Inject constructor(
3335
init {
3436
viewModelScope.launch {
3537
val fortuneId = userPreferences.fortuneIdFlow.firstOrNull()
36-
fortuneId?.let { getFortune(it) }
38+
val firstDismissedAlarmId = userPreferences.firstDismissedAlarmIdFlow.firstOrNull()
39+
val fortuneDate = userPreferences.fortuneDateFlow.firstOrNull()
40+
fortuneId?.let { getFortune(it, firstDismissedAlarmId, fortuneDate) }
3741
}
3842
}
39-
40-
private fun getFortune(fortuneId: Long) = intent {
43+
private fun getFortune(fortuneId: Long, firstDismissedAlarmId: Long?, fortuneDate: String?) = intent {
4144
updateState { copy(isLoading = true) }
4245

4346
fortuneRepository.getFortune(fortuneId).onSuccess { fortune ->
4447
val savedImageId = userPreferences.fortuneImageIdFlow.firstOrNull()
4548
val imageId = savedImageId ?: getRandomImage()
4649

4750
val formattedTitle = fortune.dailyFortuneTitle.replace(",", ",\n").trim()
51+
val todayDate = LocalDate.now().format(DateTimeFormatter.ISO_DATE)
52+
val hasReward = (fortuneDate == todayDate) && (firstDismissedAlarmId != null)
4853
updateState {
4954
copy(
5055
isLoading = false,
@@ -53,6 +58,7 @@ class FortuneViewModel @Inject constructor(
5358
avgFortuneScore = fortune.avgFortuneScore,
5459
fortunePages = fortune.toFortunePages(),
5560
fortuneImageId = imageId,
61+
hasReward = hasReward,
5662
)
5763
}
5864
}.onFailure { error ->

0 commit comments

Comments
 (0)