Repository: corona-warn-app/cwa-app-android
File: Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/main/home/HomeFragmentViewModel.kt (Kotlin)

Code before:
        }
    }
        .distinctUntilChanged()
        .asLiveData(dispatcherProvider.Default)

    // TODO only lazy to keep tests going which would break because of LocalData access
    val showLoweredRiskLevelDialog: LiveData<Boolean> by lazy {
        tracingSettings
            .isUserToBeNotifiedOfLoweredRiskLevel
            .flow
            .map { shouldBeNotified ->
                val shouldBeShown = shouldBeNotified && !isLoweredRiskLevelDialogBeingShown
                if (shouldBeShown) {
                    isLoweredRiskLevelDialogBeingShown = true
                }
                shouldBeShown
            }
            .asLiveData(context = dispatcherProvider.Default)
    }

    data class ShowAdditionalHighRiskLevelDialogEvent(
        val show: Boolean,
        val maxEncounterAgeInDays: Int
    )

    val showAdditionalHighRiskLevelDialog: LiveData<ShowAdditionalHighRiskLevelDialogEvent> by lazy {
        tracingSettings
            .isUserToBeNotifiedOfAdditionalHighRiskLevel
            .flow
            .map {
                ShowAdditionalHighRiskLevelDialogEvent(
                    show = it,
                    maxEncounterAgeInDays = appConfigProvider.getAppConfig().maxEncounterAgeInDays
                )
            }
            .asLiveData(context = dispatcherProvider.Default)
    }

    fun errorResetDialogDismissed() {
        errorResetTool.isResetNoticeToBeShown = false
    }

    fun refreshRequiredData() {
        launch {
            try {
                submissionRepository.refreshTest()
            } catch (e: CoronaTestNotFoundException) {
                Timber.e(e, "refreshTest failed")
                errorEvent.postValue(e)
            }
            tracingRepository.refreshRiskLevel()

Review comment (suggestion):
Could this lead to situations where the same dialog is created multiple times and overlays other instances?
E.g. when the livedata reconnects to the flow, like when the user puts the app into background for more than 5 seconds while the dialog is shown.

Code after:
                            when (statsItem) {
                                is LocalIncidenceAndHospitalizationStats -> {
                                    localStatisticsConfigStorage.activeSelections.update {
                                        it.withoutLocation(
                                            statsItem.selectedLocation
                                        )
                                    }
                                }
                            }
                        }
                    )
                )
            }

            add(
                CreateTraceLocationCard.Item(
                    onClickAction = {
                        events.postValue(
                            HomeFragmentEvents.OpenTraceLocationOrganizerGraph(
                                traceLocationOrganizerSettings.qrInfoAcknowledged
                            )
                        )
                    }
                )
            )

            add(FAQCard.Item(onClickAction = { events.postValue(HomeFragmentEvents.OpenFAQUrl) }))
        }
    }
        .distinctUntilChanged()
        .asLiveData(dispatcherProvider.Default)

    // TODO only lazy to keep tests going which would break because of LocalData access
    val showLoweredRiskLevelDialog: LiveData<Boolean> by lazy {
        tracingSettings
            .isUserToBeNotifiedOfLoweredRiskLevel
            .flow
            .map { shouldBeNotified ->
                val shouldBeShown = shouldBeNotified && !isLoweredRiskLevelDialogBeingShown
                if (shouldBeShown) {
                    isLoweredRiskLevelDialogBeingShown = true
                }
                shouldBeShown
            }
            .asLiveData(context = dispatcherProvider.Default)
    }

    fun errorResetDialogDismissed() {
        errorResetTool.isResetNoticeToBeShown = false
    }