@@ -18,6 +18,8 @@ import kotlinx.coroutines.launch
1818import org.orbitmvi.orbit.syntax.simple.intent
1919import org.orbitmvi.orbit.syntax.simple.postSideEffect
2020import org.orbitmvi.orbit.syntax.simple.reduce
21+ import java.time.LocalDate
22+ import java.time.format.DateTimeFormatter
2123import 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