Skip to content

Commit

Permalink
fix: 条件式を修正
Browse files Browse the repository at this point in the history
  • Loading branch information
pantasystem committed Nov 25, 2023
1 parent d0f2a8f commit e8a85f2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.mapNotNull
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import kotlinx.datetime.Clock
import kotlinx.datetime.TimeZone
import kotlinx.datetime.todayIn
import net.pantasystem.milktea.app_store.account.AccountStore
import net.pantasystem.milktea.app_store.setting.SettingStore
import net.pantasystem.milktea.common.ui.ApplyMenuTint
Expand Down Expand Up @@ -172,8 +169,6 @@ class UserDetailActivity : AppCompatActivity() {
@Inject
lateinit var userPinnedNotesFragmentFactory: UserPinnedNotesFragmentFactory

private val currentDate = Clock.System.todayIn(TimeZone.currentSystemDefault())

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
applyTheme()
Expand Down Expand Up @@ -369,10 +364,8 @@ class UserDetailActivity : AppCompatActivity() {
}
}
launch {
mViewModel.userState.mapNotNull {
it?.info?.birthday
}.collect {
if (it == currentDate) {
mViewModel.isTodayBirthday.collect {
if (it) {
binding.konfettiView.bringToFront()
binding.konfettiView.start(rain())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.launch
import kotlinx.datetime.Clock
import kotlinx.datetime.Instant
import kotlinx.datetime.TimeZone
import kotlinx.datetime.toLocalDateTime
import kotlinx.datetime.todayIn
import net.pantasystem.milktea.app_store.account.AccountStore
import net.pantasystem.milktea.common.Logger
import net.pantasystem.milktea.common.mapCancellableCatching
Expand Down Expand Up @@ -111,6 +113,13 @@ class UserDetailViewModel @Inject constructor(
_errors.tryEmit(it)
}.stateIn(viewModelScope, SharingStarted.Lazily, null)

val isTodayBirthday = userState.map {
val today = Clock.System.todayIn(TimeZone.currentSystemDefault())
it?.info?.birthday?.let { birthday ->
birthday.monthNumber == today.monthNumber && birthday.dayOfMonth == today.dayOfMonth
} ?: false
}.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), false)

val originProfileUrl = userState.filterNotNull().map {
val account = accountRepository.get(it.id.accountId).getOrThrow()
it.getRemoteProfileUrl(account)
Expand Down

0 comments on commit e8a85f2

Please sign in to comment.